Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public handleError(error, res: express.Response, next: (err?: any) => void) {
// handle known errors
if (![[ValidationErrorName, 400], [NotFoundErrorName, 404], [ConflictErrorName, 409], [NotImplementedErrorName, 405], [UnauthorizedErrorName, 401]].some((p: [string, number]) => {
let [errorName, code] = p;
if (VError.findCauseByName(error, errorName)) {
res.status(code).json({
code: code,
message: error.message
})
return true
}
return false
})) {
// or pass the error down the chain
console.error(VError.fullStack(error));
next(error)
}
}
afterEach(function () {
if (this.currentTest && this.currentTest.state === "failed") {
console.error(VError.fullStack(this.currentTest.err));
}
});
get fullStack(): string {
return VError.fullStack(this);
}
export function printError(err: Error): string {
return VError.fullStack(err);
}