Created
January 4, 2021 03:32
-
-
Save igorjs/28719eaaa1309101afaa4e7455566441 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function safeThrow( | |
target: object, | |
key: string | symbol, | |
descriptor: TypedPropertyDescriptor<(req: Request, res: Response, next: NextFunction) => Promise<any>>) { | |
const fun = descriptor.value; | |
descriptor.value = async function () { | |
try { | |
await fun.apply(this, arguments); | |
} catch (err) { | |
arguments[2](err); | |
} | |
}; | |
} | |
@safeThrow | |
private async get(req: Request, res: Response, next: NextFunction) { | |
throw { status: 404, message: 'Not supported' } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment