aboutsummaryrefslogtreecommitdiffstats
path: root/include/routing.h
diff options
context:
space:
mode:
authorAntony Woods <acron1@gmail.com>2014-12-10 17:24:13 +0000
committerAntony Woods <acron1@gmail.com>2014-12-10 17:24:13 +0000
commita1751967c33b78039fc0b602ea6c408b82346df2 (patch)
tree7a4cfab0d957cddf5c3c0b5977a1e4794ec327a1 /include/routing.h
parent21b027774e4c472d27d8726774aad1aaed95ea42 (diff)
downloadcrow-a1751967c33b78039fc0b602ea6c408b82346df2.tar.gz
crow-a1751967c33b78039fc0b602ea6c408b82346df2.zip
Added a general purpose try-catch around handle() for instances where an exception would cause the server to never return a response. At some later date we would possibly still wish to provide a custom hook for dealing with 500s. Also note, after an exception is caught, the generated 500 response is still sent to middleware handlers
Diffstat (limited to 'include/routing.h')
-rw-r--r--include/routing.h20
1 files changed, 19 insertions, 1 deletions
diff --git a/include/routing.h b/include/routing.h
index 9f607f1..79743cd 100644
--- a/include/routing.h
+++ b/include/routing.h
@@ -655,7 +655,25 @@ public:
CROW_LOG_DEBUG << "Matched rule '" << ((TaggedRule<>*)rules_[rule_index].get())->rule_ << "' " << (uint32_t)req.method << " / " << rules_[rule_index]->methods();
- rules_[rule_index]->handle(req, res, found.second);
+ // any uncaught exceptions become 500s
+ try
+ {
+ rules_[rule_index]->handle(req, res, found.second);
+ }
+ catch(std::exception& e)
+ {
+ CROW_LOG_ERROR << "An uncaught exception occurred: " << e.what();
+ res = response(500);
+ res.end();
+ return;
+ }
+ catch(...)
+ {
+ CROW_LOG_ERROR << "An uncaught exception occurred. The type was unknown so no information was available.";
+ res = response(500);
+ res.end();
+ return;
+ }
}
void debug_print()