]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Webserver: try harder to always return *some* response
authorChristian Hofstaedtler <christian@hofstaedtler.name>
Mon, 10 Mar 2014 10:59:39 +0000 (11:59 +0100)
committerChristian Hofstaedtler <christian@hofstaedtler.name>
Mon, 10 Mar 2014 10:59:39 +0000 (11:59 +0100)
Even a 500 is better than a connection reset.

pdns/webserver.cc
pdns/webserver.hh

index 0c18cd2ccb283b6b7899fcce0b9af467d342beb0..44c668733ec26149899cf3c9d72b15d81c764056 100644 (file)
@@ -229,7 +229,21 @@ HttpResponse WebServer::handleRequest(HttpRequest req)
       throw HttpNotFoundException();
     }
 
-    (*handler)(&req, &resp);
+    try {
+      (*handler)(&req, &resp);
+    }
+    catch(PDNSException &e) {
+      L<<Logger::Error<<"HTTP ISE for \""<< req.url.path << "\": Exception: " << e.reason << endl;
+      throw HttpInternalServerErrorException();
+    }
+    catch(std::exception &e) {
+      L<<Logger::Error<<"HTTP ISE for \""<< req.url.path << "\": STL Exception: " << e.what() << endl;
+      throw HttpInternalServerErrorException();
+    }
+    catch(...) {
+      L<<Logger::Error<<"HTTP ISE for \""<< req.url.path << "\": Unknown Exception" << endl;
+      throw HttpInternalServerErrorException();
+    }
   }
   catch(HttpException &e) {
     resp = e.response();
index d56c1120d7c7eb2ccba65e18915dc7f4c9dbaca3..9dc7a397b90c0bf1467bca6735eab280fa7ce034 100644 (file)
@@ -94,6 +94,11 @@ public:
   HttpMethodNotAllowedException() : HttpException(405) { };
 };
 
+class HttpInternalServerErrorException : public HttpException {
+public:
+  HttpInternalServerErrorException() : HttpException(500) { };
+};
+
 class ApiException : public runtime_error
 {
 public: