rethrow on promise rejections

This commit is contained in:
Timo Hocker 2020-03-09 12:55:39 +01:00
parent 4d58e47679
commit 6e529676fe
7 changed files with 7 additions and 14 deletions

2
.gitignore vendored
View File

@ -1 +1,3 @@
/node_modules/
/coverage/
/.nyc_output/

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
{"parent":"9ed529ca-95a3-4f3d-a58a-4f5f1df16472","pid":16968,"argv":["/usr/bin/node","/home/timo/dev/requestor/node_modules/ava/lib/worker/subprocess.js"],"execArgv":[],"cwd":"/home/timo/dev/requestor","time":1582545546386,"ppid":16957,"coverageFilename":"/home/timo/dev/requestor/.nyc_output/5ad64ed6-f8ad-4aa6-a4ce-4978c9a74881.json","externalId":"","uuid":"5ad64ed6-f8ad-4aa6-a4ce-4978c9a74881","files":["/home/timo/dev/requestor/index.js","/home/timo/dev/requestor/test_files/root/all-root.js","/home/timo/dev/requestor/test_files/root/delete-root.js","/home/timo/dev/requestor/test_files/root/get-root.js","/home/timo/dev/requestor/test_files/root/not-root.js","/home/timo/dev/requestor/test_files/root/post-root.js","/home/timo/dev/requestor/test_files/root/put-root.js","/home/timo/dev/requestor/test_files/root.sub/all-root.sub.js","/home/timo/dev/requestor/test_files/root.sub/delete-root.sub.js","/home/timo/dev/requestor/test_files/root.sub/get-root.sub.js","/home/timo/dev/requestor/test_files/root.sub/not-root.sub.js","/home/timo/dev/requestor/test_files/root.sub/post-root.sub.js","/home/timo/dev/requestor/test_files/root.sub/put-root.sub.js","/home/timo/dev/requestor/test_files/sub/all-sub.js","/home/timo/dev/requestor/test_files/sub/all-sub.root.js","/home/timo/dev/requestor/test_files/sub/delete-sub.js","/home/timo/dev/requestor/test_files/sub/get-sub.js","/home/timo/dev/requestor/test_files/sub/get-sub.lv1.lv2.lv3.js","/home/timo/dev/requestor/test_files/sub/not-sub.js","/home/timo/dev/requestor/test_files/sub/post-sub.js","/home/timo/dev/requestor/test_files/sub/put-sub.js"]}

View File

@ -1 +0,0 @@
{"parent":null,"pid":16957,"argv":["/usr/bin/node","/home/timo/dev/requestor/node_modules/.bin/ava"],"execArgv":[],"cwd":"/home/timo/dev/requestor","time":1582545545515,"ppid":16946,"coverageFilename":"/home/timo/dev/requestor/.nyc_output/9ed529ca-95a3-4f3d-a58a-4f5f1df16472.json","externalId":"","uuid":"9ed529ca-95a3-4f3d-a58a-4f5f1df16472","files":[]}

View File

@ -1 +0,0 @@
{"processes":{"5ad64ed6-f8ad-4aa6-a4ce-4978c9a74881":{"parent":"9ed529ca-95a3-4f3d-a58a-4f5f1df16472","children":[]},"9ed529ca-95a3-4f3d-a58a-4f5f1df16472":{"parent":null,"children":["5ad64ed6-f8ad-4aa6-a4ce-4978c9a74881"]}},"files":{"/home/timo/dev/requestor/index.js":["5ad64ed6-f8ad-4aa6-a4ce-4978c9a74881"],"/home/timo/dev/requestor/test_files/root/all-root.js":["5ad64ed6-f8ad-4aa6-a4ce-4978c9a74881"],"/home/timo/dev/requestor/test_files/root/delete-root.js":["5ad64ed6-f8ad-4aa6-a4ce-4978c9a74881"],"/home/timo/dev/requestor/test_files/root/get-root.js":["5ad64ed6-f8ad-4aa6-a4ce-4978c9a74881"],"/home/timo/dev/requestor/test_files/root/not-root.js":["5ad64ed6-f8ad-4aa6-a4ce-4978c9a74881"],"/home/timo/dev/requestor/test_files/root/post-root.js":["5ad64ed6-f8ad-4aa6-a4ce-4978c9a74881"],"/home/timo/dev/requestor/test_files/root/put-root.js":["5ad64ed6-f8ad-4aa6-a4ce-4978c9a74881"],"/home/timo/dev/requestor/test_files/root.sub/all-root.sub.js":["5ad64ed6-f8ad-4aa6-a4ce-4978c9a74881"],"/home/timo/dev/requestor/test_files/root.sub/delete-root.sub.js":["5ad64ed6-f8ad-4aa6-a4ce-4978c9a74881"],"/home/timo/dev/requestor/test_files/root.sub/get-root.sub.js":["5ad64ed6-f8ad-4aa6-a4ce-4978c9a74881"],"/home/timo/dev/requestor/test_files/root.sub/not-root.sub.js":["5ad64ed6-f8ad-4aa6-a4ce-4978c9a74881"],"/home/timo/dev/requestor/test_files/root.sub/post-root.sub.js":["5ad64ed6-f8ad-4aa6-a4ce-4978c9a74881"],"/home/timo/dev/requestor/test_files/root.sub/put-root.sub.js":["5ad64ed6-f8ad-4aa6-a4ce-4978c9a74881"],"/home/timo/dev/requestor/test_files/sub/all-sub.js":["5ad64ed6-f8ad-4aa6-a4ce-4978c9a74881"],"/home/timo/dev/requestor/test_files/sub/all-sub.root.js":["5ad64ed6-f8ad-4aa6-a4ce-4978c9a74881"],"/home/timo/dev/requestor/test_files/sub/delete-sub.js":["5ad64ed6-f8ad-4aa6-a4ce-4978c9a74881"],"/home/timo/dev/requestor/test_files/sub/get-sub.js":["5ad64ed6-f8ad-4aa6-a4ce-4978c9a74881"],"/home/timo/dev/requestor/test_files/sub/get-sub.lv1.lv2.lv3.js":["5ad64ed6-f8ad-4aa6-a4ce-4978c9a74881"],"/home/timo/dev/requestor/test_files/sub/not-sub.js":["5ad64ed6-f8ad-4aa6-a4ce-4978c9a74881"],"/home/timo/dev/requestor/test_files/sub/post-sub.js":["5ad64ed6-f8ad-4aa6-a4ce-4978c9a74881"],"/home/timo/dev/requestor/test_files/sub/put-sub.js":["5ad64ed6-f8ad-4aa6-a4ce-4978c9a74881"]},"externalIds":{}}

View File

@ -33,15 +33,11 @@ function get_handler ({ module_folder, file, opts, rethrow }) {
const handler = require (path.join (process.cwd (), module_folder, file));
return (req, res, next) => {
try {
handler (req, res, next, opts);
}
catch (e) {
new Promise ((res) => res(handler (req, res, next, opts)))
.catch ((e) => {
if (rethrow)
throw e;
else
console.error (e);
}
});
};
}