summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 )