shellscape/koa-webpack

Koa errors generate Unhandled promise rejection warnings

ewrogers opened this issue · 3 comments

  • Node Version: 7.9.0
  • NPM Version: 4.2.0
  • koa Version: 2.2.0
  • koa-wepback Version: 0.4.0

Issue

koa-webpack middleware generates UnhandledPromiseRejectionWarning warnings when errors are raised in Koa apps. This happens in even the most trivial of webpack/app setups.

Removing the koa-webpack middleware makes the issue go away.

Expected Behavior

Unhandled promise rejections should be handed so that no warnings should be generated.

Actual Behavior

(node:1642) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Can't set headers after they are sent.
(node:1642) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

How can we reproduce the behavior?

Attach the koa-webpack middleware and access an invalid (404) route to see the warning appear in the console.

I haven't run into this yet, so I'd like to see a repo or gist that could be used to reproduce this. I'm not sure I'd agree that errors should throw 40x, as Koa should handle anything not found. 50x might be more appropriate.

My apologies, I think it's actually some combination of koa-static with koa-webpack. Trying to reproduce it and turning off the static files did the trick. Will investigate further and update.

UPDATE: Seems that when using koa-static, the { defer: true } option should be set to avoid this warning (allowing downstream middleware to take precedence).

No worries. Should we close this one? Also, do you think there is anything we could add to the README to benefit others based on your findings?