Hi @vsipranav-0854,
As you stated, error
is an optional parameter for onclose and is only populated when connection is closed due to an actual error. The code snippet you provided seems perfectly fine to me.
Regards,
Ryan
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello,
I am trying to implement simple chat application using SignalR. For front-end, I am using Angular 10 with Typescript SignalR client. For this client I am using the latest @microsoft/signalr package. While the back-end server is in .Net Core 3.1 WebAPI project. Also, I am using the Azure SignalR service with Standard pricing tier.
I am referring the following documentation.
https://learn.microsoft.com/en-us/javascript/api/@microsoft/signalr/hubconnection?view=signalr-js-latest#onclose--error---error-----void-
As per the documentation, the 'onclose' event receives an optional error parameter if there is any. But in my case in the client code, I am always getting this error as 'undefined'. I want to use this error parameter to determine if the connection was closed purposefully by client or was there any error either from client or server and based on that I want to take the further action in code. Find below my code snippet.
this.hubConnection.onclose((error) => {
// Try to log the error.
if (typeof error !== 'undefined') {
console.log(this.TAG + '(onclose) Error: ' + error.name + ' : ' + error.message);
} else {
console.log(this.TAG + '(onclose) No error to show while closing the connection.');
}
// Log the connection state.
console.log(this.TAG + '(onclose) HubConnection State: ' + this.hubConnection.state);
});
Kindly please take a look at this and let me know if I am doing it correctly or is there any other way to do this. Also, if you need more details about the issue, please let me know.
Thanks.
Hi @vsipranav-0854,
As you stated, error
is an optional parameter for onclose and is only populated when connection is closed due to an actual error. The code snippet you provided seems perfectly fine to me.
Regards,
Ryan