Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ES6 async Router is not capturing the catch properly #3026

Closed
natarajanmca11 opened this issue Jun 22, 2016 · 2 comments
Closed

ES6 async Router is not capturing the catch properly #3026

natarajanmca11 opened this issue Jun 22, 2016 · 2 comments
Labels

Comments

@natarajanmca11
Copy link

I am using the following code. Global error handler not getting call If any error happens in service.

class UserRoute {
    public static async AddNewUser(req: Request, res: Response, next: NextFunction): Promise<void> {
        const service = ServiceFactory.CreateService(UserService, req);
        let v = await service.AddUser(req.body)
        res.send(v);
    }
}

let router: Router = express.Router();
router.post('/' + UserRoute.AddNewUser.name, UserRoute.AddNewUser);
export default router;
@frogcjn
Copy link

frogcjn commented Jun 25, 2016

@natarajanmca11 You should wrap it. Express does not support async/promise function.
See use promise in http://expressjs.com/en/advanced/best-practice-performance.html#promises
And there is also an article mentioned in this page, https://strongloop.com/strongblog/async-error-handling-expressjs-es7-promises-generators/

@blakeembrey
Copy link
Member

To work around this for now, you can use something like https://github.com/blakeembrey/async-middleware. For native support, you might want to follow #2259.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants