summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2018-02-10 15:40:46 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2018-02-11 13:41:40 +0000
commit273631e0575d0cee72bab3d2d65398b20868435c (patch)
tree5bbffb412dbdd2e75c39404d0c83b107868438f6
parentRemove non-sense test route with conflicting path/method (diff)
downloadicespider-273631e0575d0cee72bab3d2d65398b20868435c.tar.bz2
icespider-273631e0575d0cee72bab3d2d65398b20868435c.tar.xz
icespider-273631e0575d0cee72bab3d2d65398b20868435c.zip
Default 500 error handler
Don't write .what() into the HTTP status header... it might contain things that aren't valid there. Instead, write the class name there and write .what() in the response body.
-rw-r--r--icespider/core/core.cpp12
-rw-r--r--icespider/core/core.h3
-rw-r--r--icespider/unittests/testApp.cpp8
3 files changed, 19 insertions, 4 deletions
diff --git a/icespider/core/core.cpp b/icespider/core/core.cpp
index a822366..d63464e 100644
--- a/icespider/core/core.cpp
+++ b/icespider/core/core.cpp
@@ -102,7 +102,17 @@ namespace IceSpider {
std::cerr << "Error handler failed" << std::endl;
}
}
- request->response(500, exception.what());
+ defaultErrorReport(request, exception);
+ }
+
+ 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();
request->dump(std::cerr);
}
diff --git a/icespider/core/core.h b/icespider/core/core.h
index 4aac640..f358009 100644
--- a/icespider/core/core.h
+++ b/icespider/core/core.h
@@ -33,6 +33,9 @@ namespace IceSpider {
Ice::ObjectAdapterPtr pluginAdapter;
static const boost::filesystem::path defaultConfig;
+
+ private:
+ void defaultErrorReport(IHttpRequest * request, const std::exception & ex) const;
};
class DLL_PUBLIC CoreWithDefaultRouter : public Core {
diff --git a/icespider/unittests/testApp.cpp b/icespider/unittests/testApp.cpp
index 90e7737..5832595 100644
--- a/icespider/unittests/testApp.cpp
+++ b/icespider/unittests/testApp.cpp
@@ -523,9 +523,11 @@ BOOST_AUTO_TEST_CASE( testErrorHandler_Unhandled )
TestRequest requestDeleteItem(this, HttpMethod::DELETE, "/error");
process(&requestDeleteItem);
auto h = requestDeleteItem.getResponseHeaders();
- BOOST_REQUIRE_EQUAL(h["Status"], "500 test error");
- requestDeleteItem.output.get();
- BOOST_REQUIRE(requestDeleteItem.output.eof());
+ BOOST_REQUIRE_EQUAL(h["Status"], "500 TestIceSpider::Ex");
+ 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_AUTO_TEST_CASE( testErrorHandler_Handled1 )