Repository navigation
Add errorHandler option - #5
sjoerdsmink wants to merge 6 commits into
Conversation
Add errorHandler option for adapter creation
|
Actually, I think we should rather remove the "error" events, as the end user has no constructive way to handle them. See #7. What do you think? |
|
I rewrote the code a bit to use an I think the benefit of using an errorHandler instead of removing all error events in #7 is that I can now log the errors. That is really useful for debugging, but also when going through server logging. I can understand your reasoning of not letting the server crash, but how would you feel about using the |
Before:
```js
io.adapter(createAdapter(pool));
io.of("/").adapter.on("error", () => {
// needed so that no exception is thrown in case of error
});
```
After:
```js
io.adapter(createAdapter(pool, {
errorHandler: (err) => {
// ...
}
}));
```
|
Merged as ec1b78c. Thanks! |
It might happen that:
There is code to reconnect, but that's not executed as an uncaughtException is thrown. This is because
this.emit("error", err);will cause the Node process to exit, as explained on https://nodejs.org/api/events.html#error-eventsIt would be better to offer the option to handle these errors.
Alternative would be to mention in the readme that errors can be handled when creating the adapter:
The arrow notation (so
io.adapter((nsp) => {instead ofio.adapter(function (nsp) {) won't work in this case.