molnarg / node-http2

An HTTP/2 client and server implementation for node.js
MIT License
1.79k stars 185 forks source link

emit error events instead of throwing Error #180

Closed felicienfrancois closed 8 years ago

felicienfrancois commented 8 years ago

Methods of EventEmitters should not throw Errors but emit error events instead. On top of being the recommended way to throw errors in EventEmitters, this is needed to be able to handle thoose errors. Some errors may happen randomly or may be due to external sources (server or libraries). A typical usecase is forwarding http/2 requests and response (thoose can contains minor errors like deprecated headers or invalid frame or whatever and it should not crash the server ...)

Currently thoose errors are not catchable (because they are thrown from asynchronous or nested methods). Emiting error event allow to handle errors (by listening to error event) while keeping the original behavior (throwing error) if error event is not listened to

This PR apply this for a few errors.