aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--amalgamate/crow_all.h20
-rw-r--r--include/routing.h20
2 files changed, 38 insertions, 2 deletions
diff --git a/amalgamate/crow_all.h b/amalgamate/crow_all.h
index 911d15d..ed5ee0d 100644
--- a/amalgamate/crow_all.h
+++ b/amalgamate/crow_all.h
@@ -6966,7 +6966,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()
diff --git a/include/routing.h b/include/routing.h
index f074b69..a2e7856 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()