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

Middleware - error handling #27

Open
javorka opened this issue Mar 15, 2017 · 1 comment
Open

Middleware - error handling #27

javorka opened this issue Mar 15, 2017 · 1 comment

Comments

@javorka
Copy link

javorka commented Mar 15, 2017

Hi,
I'm trying to create simple error handling middleware like this:

io.use( async ( ctx, next ) => {
  try {
    await next();
  } catch (err) {
    console.log('OUCH, ERROR OCCURRED', err.message);
  }
});

I'm using async/await stuff (on latest Node - without babel or harmony flag), but I still get UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property ...

I also tried your provided example of middleware - logging response time, and it works. Please, can you help me with this issue?

@lucasmacosta
Copy link

+1 I have the same issue, composing the error handler with others middlewares using koa-compose and using that as event handler works but by itself it does not.

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

No branches or pull requests

2 participants