Skip to content

Commit

Permalink
refactor: rename ERROR to CONNECT_ERROR
Browse files Browse the repository at this point in the history
The meaning is not modified: this packet type is still used by the
server when the connection to a namespace is refused.
  • Loading branch information
darrachequesne committed Oct 25, 2020
1 parent 5c73733 commit d16c035
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/client.ts
Expand Up @@ -91,7 +91,7 @@ export class Client {
} else {
debug("creation of namespace %s was denied", name);
this._packet({
type: PacketType.ERROR,
type: PacketType.CONNECT_ERROR,
nsp: name,
data: "Invalid namespace"
});
Expand Down
6 changes: 3 additions & 3 deletions lib/socket.ts
Expand Up @@ -12,8 +12,8 @@ import base64id from "base64id";
const debug = debugModule("socket.io:socket");

export const RESERVED_EVENTS = new Set([
"error",
"connect",
"connect_error",
"disconnect",
"disconnecting",
// EventEmitter reserved events: https://nodejs.org/api/events.html#events_event_newlistener
Expand Down Expand Up @@ -316,7 +316,7 @@ export class Socket extends EventEmitter {
this.ondisconnect();
break;

case PacketType.ERROR:
case PacketType.CONNECT_ERROR:
this._onerror(new Error(packet.data));
}
}
Expand Down Expand Up @@ -438,7 +438,7 @@ export class Socket extends EventEmitter {
* @private
*/
_error(err) {
this.packet({ type: PacketType.ERROR, data: err });
this.packet({ type: PacketType.CONNECT_ERROR, data: err });
}

/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -39,7 +39,7 @@
"debug": "~4.1.0",
"engine.io": "~4.0.0",
"socket.io-adapter": "2.0.3-rc2",
"socket.io-parser": "4.0.1-rc2"
"socket.io-parser": "4.0.1-rc3"
},
"devDependencies": {
"@types/cookie": "^0.4.0",
Expand Down
4 changes: 2 additions & 2 deletions test/socket.io.ts
Expand Up @@ -1711,8 +1711,8 @@ describe("socket.io", () => {
srv.listen(() => {
const socket = client(srv);
sio.on("connection", s => {
expect(() => s.emit("error")).to.throwException(
/"error" is a reserved event name/
expect(() => s.emit("connect_error")).to.throwException(
/"connect_error" is a reserved event name/
);
socket.close();
done();
Expand Down

0 comments on commit d16c035

Please sign in to comment.