Signalr: HTTP Status codes

Created on 18 Dec 2015  路  2Comments  路  Source: SignalR/SignalR

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.

Most helpful comment

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"}

All 2 comments

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 :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

VrindiTeam picture VrindiTeam  路  3Comments

Shahrooze picture Shahrooze  路  9Comments

markrendle picture markrendle  路  4Comments

JoergTiedemann picture JoergTiedemann  路  3Comments

DOMZE picture DOMZE  路  4Comments