From 9144f234f0cde55398d19696e42da8dea9c7bade Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 10 Feb 2018 15:40:46 +0000 Subject: Default 500 error handler Include the exception class name in the error report into the default error page. Write the same output to the error log after the request dump. --- icespider/core/core.cpp | 7 +++++-- icespider/unittests/testApp.cpp | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/icespider/core/core.cpp b/icespider/core/core.cpp index d63464e..057faa6 100644 --- a/icespider/core/core.cpp +++ b/icespider/core/core.cpp @@ -4,6 +4,7 @@ #include #include #include +#include INSTANTIATEFACTORY(IceSpider::Plugin, Ice::CommunicatorPtr, Ice::PropertiesPtr); INSTANTIATEPLUGINOF(IceSpider::ErrorHandler); @@ -105,15 +106,17 @@ namespace IceSpider { defaultErrorReport(request, exception); } + AdHocFormatter(LogExp, "Exception type: %?\nDetail: %?\n"); void Core::defaultErrorReport(IHttpRequest * request, const std::exception & exception) const { char * buf = __cxxabiv1::__cxa_demangle(typeid(exception).name(), NULL, NULL, NULL); request->setHeader("Content-Type", "text/plain"); request->response(500, buf); - free(buf); - request->getOutputStream() << exception.what(); + LogExp::write(request->getOutputStream(), buf, exception.what()); request->dump(std::cerr); + LogExp::write(std::cerr, buf, exception.what()); + free(buf); } Ice::ObjectPrx diff --git a/icespider/unittests/testApp.cpp b/icespider/unittests/testApp.cpp index 5832595..9714d33 100644 --- a/icespider/unittests/testApp.cpp +++ b/icespider/unittests/testApp.cpp @@ -527,7 +527,7 @@ BOOST_AUTO_TEST_CASE( testErrorHandler_Unhandled ) BOOST_REQUIRE_EQUAL(h["Content-Type"], "text/plain"); auto & o = requestDeleteItem.output; auto b = o.str().substr(o.tellg()); - BOOST_REQUIRE_EQUAL(b, "test error"); + BOOST_REQUIRE_EQUAL(b, "Exception type: TestIceSpider::Ex\nDetail: test error\n"); } BOOST_AUTO_TEST_CASE( testErrorHandler_Handled1 ) -- cgit v1.2.3