1
0
Fork 0

Better handle wrapped errors in Foxx

This commit is contained in:
Alan Plum 2016-04-13 15:23:32 +02:00
parent 30d6200a60
commit 3fdd0a90e2
No known key found for this signature in database
GPG Key ID: 8ED72A9A323B6EFD
1 changed files with 13 additions and 1 deletions

View File

@ -178,10 +178,22 @@ module.exports = class FoxxService {
console.errorLines(e.stack);
error = new InternalServerError();
error.cause = e;
let err = e;
while (err.cause && err.cause.stack) {
err = err.cause;
console.errorLines(`via ${err.stack}`);
}
} else if (e.statusCode >= 500) {
console.warnLines(e.stack);
let err = e;
while (err.cause && err.cause.stack) {
err = err.cause;
console.warnLines(`via ${err.stack}`);
}
}
const body = {
error: true,
errorNum: error.statusCode,
errorNum: error.errorNum || error.statusCode,
errorMessage: error.message,
code: error.statusCode
};