-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/unknown 404 #297
base: rc-1.5.0
Are you sure you want to change the base?
Feature/unknown 404 #297
Conversation
Signed-off-by: thanaParis <[email protected]>
Signed-off-by: thanaParis <[email protected]>
/** | ||
* See {@link IUpgradeError.terminateConnection} | ||
**/ | ||
error?.terminateConnection?.(socket) || this._terminateConnectionInternalError(socket); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isnt the left and the right of the ||
operator, always going to fire? I am seeing that error?.terminateConnection
returns void, doesnt that mean that the right side will fire unintentionally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it be cleaner to move:
terminateConnection(socket: Duplex): void {
socket.write('HTTP/1.1 401 Unauthorized\r\n');
socket.write(
'WWW-Authenticate: Basic realm="Access to the WebSocket", charset="UTF-8"\r\n',
);
socket.write('\r\n');
socket.end();
socket.destroy();
}
as a helper method along with this._terminateConnectionInternalError
and instead maybe do something like:
if (error instanceOf UpgradeAuthenticationError) {
this.terminateAuthenticationError();
} else {
this.terminateConnectionError();
}
the two functions are more or less the same and it feels a bit odd that the socket handling is in the error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah I see, there is also UpgradeUnknownError, but maybe there can be a handle helper function here like:
terminateConnectionHelper(socket: Duplex, str1 = 'HTTP/1.1 500 Internal Server Error', str2 = ''): void {
socket.write('${str1}\r\n');
socket.write(
'${str2}\r\n',
);
socket.write('\r\n');
socket.end();
socket.destroy();
}
and then just:
if (error instanceOf UpgradeAuthenticationError) {
this.terminateConnectionHelper(socket, 'HTTP/1.1 401 Unauthorized', ''WWW-Authenticate: Basic realm="Access to the WebSocket", charset="UTF-8"');
} else if (error instanceOf UpgradeUnknownError) {
this.terminateConnectionHelper(socket, 'HTTP/1.1 404 Not Found');
} else {
this.terminateConnectionHelper(socket);
}
From the OCPP 2.0.1 specification:
Citrine previously always gave a 401, this pr gives a 404 when the charger is unknown and 500 when the server itself has an error.