handle async route errors

Related to #487
This commit is contained in:
Nico Rehwaldt
2018-10-20 22:40:21 +02:00
parent e5d7d8ab2b
commit 464924ed67
3 changed files with 18 additions and 1 deletions

View File

@@ -53,7 +53,12 @@ export function get_server_route_handler(routes: ServerRoute[]) {
};
try {
handle_method(req, res, handle_next);
const result = handle_method(req, res, handle_next);
// catch failures in async functions
if (Promise.resolve(result) === result) {
result.catch(handle_next);
}
} catch (err) {
handle_next(err);
}