Is there any way to get the HTTP status code from an error? I need to do different actions based on the type of error. For example, a 500 error should take the user to an error page. While a 401 error should take the user to the login page. I am using the code below to catch errors on the hub.
connection.error(function (error) {
console.log(error);
});
This results in a pretty generic message Error during negotiation request.
After digging around in the jquery.signalR.js source code I was able to find what I was looking for.
connection.error(function (error) {
console.log(error.source);
});
error.source will return an object like this {readyState: 4, responseText: "", status: 401, statusText: "Unauthorized"}
Thank you for sharing! Just helped us to fix the SwiftR, which was swallowing the error details if those were not a string :)
Most helpful comment
After digging around in the jquery.signalR.js source code I was able to find what I was looking for.
error.sourcewill return an object like this{readyState: 4, responseText: "", status: 401, statusText: "Unauthorized"}