add rethrow option
This commit is contained in:
parent
eabb5705bd
commit
58c390fc61
13
index.js
13
index.js
@ -8,6 +8,7 @@ const path = require ('path');
|
||||
* @property {any} [opts] object to pass to the handlers
|
||||
* @property {string} [subdir] subdirectory for all requests
|
||||
* @property {boolean} [verbose] enable verbose logging
|
||||
* @property {boolean} [rethrow] rethrow errors (default: true)
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -20,9 +21,9 @@ const path = require ('path');
|
||||
module.exports = function main (
|
||||
app,
|
||||
modulefolder,
|
||||
options = { opts: null, subdir: '', verbose: false }
|
||||
options = { opts: null, subdir: '', verbose: false, rethrow: true }
|
||||
) {
|
||||
const { opts, subdir, verbose } = options;
|
||||
const { opts, subdir, verbose, rethrow } = options;
|
||||
|
||||
for (const f of fs.readdirSync (modulefolder)) {
|
||||
const regex = /(?<method>.*?)-(?<url>.*?)\.js/u;
|
||||
@ -42,7 +43,15 @@ module.exports = function main (
|
||||
const handler = require (path.join (process.cwd (), modulefolder, f));
|
||||
|
||||
const requestor_handler = (req, res, next) => {
|
||||
try {
|
||||
handler (req, res, next, opts);
|
||||
}
|
||||
catch (e) {
|
||||
if (rethrow)
|
||||
throw e;
|
||||
else
|
||||
console.error (e);
|
||||
}
|
||||
};
|
||||
|
||||
if (verbose)
|
||||
|
Reference in New Issue
Block a user