feat: emit an Error object upon middleware error
This commit restores the ability to send additional data in the
middleware functions, which was removed during the rewrite to
Typescript ([1]).
The only difference with the previous implementation is that the client
will now emit a "connect_error" (previously, "error") event with an
actual Error object, with both the message and an optional "data"
attribute.
```js
// server-side
io.use((socket, next) => {
const err = new Error("not authorized");
err.data = { content: "Please retry later" };
next(err);
});
// client-side
socket.on("connect_error", err => {
console.log(err.message); // not authorized
console.log(err.data.content); // Please retry later
});
```
[1]: https://github.com/socketio/socket.io/commit/a5581a978979ff2c2c53dacdc931e7025c5d6adb D
Damien Arrachequesne committed
54bf4a44e9e896dfb64764ee7bd4e8823eb7dc7b
Parent: aa7574f