I write a function to handle exceptions thrown from async functions like:
protected safeAsync(f : e.RequestHandler) : e.RequestHandler {
/* how to detect if `f` is an async function here ?? */
const binded = f.bind(this);
return async function innerCall(req : e.Request, res : e.Response, next : Function) {
try {
return await binded(req, res, next);
} catch (err) {
log.debug(err);
return next(err);
}
}
}
The parameter f is supposed be an async function, such as
public async signupPost(req : e.Request, res : e.Response, next : Function) {/*...*/}
My question is:
In safeAsync, is there a way to detect if f is an async function, so I can log unexpected call to safeAsync ?
fhas anasynckeyword or not. You should still be able to await it as long as it returns a promise.