{"action":"created","issue":{"url":"https://api.github.com/repos/sockjs/sockjs-client/issues/268","labels_url":"https://api.github.com/repos/sockjs/sockjs-client/issues/268/labels{/name}","comments_url":"https://api.github.com/repos/sockjs/sockjs-client/issues/268/comments","events_url":"https://api.github.com/repos/sockjs/sockjs-client/issues/268/events","html_url":"https://github.com/sockjs/sockjs-client/issues/268","id":115328694,"number":268,"title":"401 response on initial handshake","user":{"login":"blittle","id":1566869,"avatar_url":"https://avatars.githubusercontent.com/u/1566869?v=3","gravatar_id":"","url":"https://api.github.com/users/blittle","html_url":"https://github.com/blittle","followers_url":"https://api.github.com/users/blittle/followers","following_url":"https://api.github.com/users/blittle/following{/other_user}","gists_url":"https://api.github.com/users/blittle/gists{/gist_id}","starred_url":"https://api.github.com/users/blittle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blittle/subscriptions","organizations_url":"https://api.github.com/users/blittle/orgs","repos_url":"https://api.github.com/users/blittle/repos","events_url":"https://api.github.com/users/blittle/events{/privacy}","received_events_url":"https://api.github.com/users/blittle/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-11-05T17:02:47Z","updated_at":"2015-11-05T18:44:31Z","closed_at":"2015-11-05T18:44:31Z","body":"I am trying to make a connection to a server but would like to know when the connection is a 401 response versus a 404. I'd like to force the user to login if it is 401 and if 404 I'd like to gradually back off on retrying to connect to the server.\r\n\r\n```javascript\r\nfunction tryConnect(url, observer) {\r\n\tsock = new SockJS(url);\r\n\r\n\tsock.onopen = function() {\r\n\t\tobserver.onNext();\r\n\t}\r\n\tsock.onclose = function() {\r\n\t\tobserver.onError('Lost connection');\r\n\t}\r\n\tsock.onerror = function(e) {\r\n\t\tobserver.onError(e)\r\n\t}\r\n}\r\n```\r\n\r\nIs there any way that I can get the server response code to bubble to either the onclose or onerror handler? The debug log output of my connection is:\r\n\r\n```\r\nsockjs-client:main using url +0ms https://localhost/ws?csrfToken=hrc706ilsrbg6tehcv1jmst6pv\r\nsockjs-client:utils:url same +3ms https://localhost/ws?csrfToken=hrc706ilsrbg6tehcv1jmst6pv https://localhost/#/tabs/0/dashboard?_k=lyjzqn false\r\nsockjs-client:info-receiver https://localhost/ws?csrfToken=hrc706ilsrbg6tehcv1jmst6pv +2ms\r\nsockjs-client:info-receiver doXhr +253ms https://localhost/ws/info?csrfToken=hrc706ilsrbg6tehcv1jmst6pv\r\nsockjs-client:browser:xhr GET +1ms https://localhost/ws/info?csrfToken=hrc706ilsrbg6tehcv1jmst6pv\r\nsockjs-client:browser:xhr withCredentials +23ms\r\nGET https://localhost/ws/info?csrfToken=hrc706ilsrbg6tehcv1jmst6pv&t=1446742316156 401 (Unauthorized)\r\nsockjs-client:browser:xhr readyState +26ms 2\r\nsockjs-client:browser:xhr readyState +1ms 3\r\nsockjs-client:browser:xhr status +1ms 401\r\nsockjs-client:browser:xhr readyState +5ms 4\r\nsockjs-client:browser:xhr status +0ms 401\r\nsockjs-client:browser:xhr finish +1ms 401 Error 401: Unauthorized\r\nsockjs-client:info-receiver finish +1ms undefined undefined\r\nsockjs-client:info-receiver _cleanup +2ms\r\nsockjs-client:main _receiveInfo +1ms undefined\r\nsockjs-client:main _close +2ms undefined 1002 Cannot connect to server undefined 0\r\nsockjs-client:browser:xhr cleanup +2ms\r\nsockjs-client:main disconnected +8s\r\n```\r\n\r\nEDIT:\r\n\r\nThe `onerror` callback is never fired and while the `onclose` callback is fired with the following event object:\r\n```javascript\r\n{\r\n    \"type\": \"close\",\r\n    \"bubbles\": false,\r\n    \"cancelable\": false,\r\n    \"timeStamp\": 1446743429350,\r\n    \"wasClean\": false,\r\n    \"code\": 1002,\r\n    \"reason\": \"Cannot connect to server\"\r\n}\r\n```\r\nThis is identical to the error object when the socket server is not present."},"comment":{"url":"https://api.github.com/repos/sockjs/sockjs-client/issues/comments/154149415","html_url":"https://github.com/sockjs/sockjs-client/issues/268#issuecomment-154149415","issue_url":"https://api.github.com/repos/sockjs/sockjs-client/issues/268","id":154149415,"user":{"login":"blittle","id":1566869,"avatar_url":"https://avatars.githubusercontent.com/u/1566869?v=3","gravatar_id":"","url":"https://api.github.com/users/blittle","html_url":"https://github.com/blittle","followers_url":"https://api.github.com/users/blittle/followers","following_url":"https://api.github.com/users/blittle/following{/other_user}","gists_url":"https://api.github.com/users/blittle/gists{/gist_id}","starred_url":"https://api.github.com/users/blittle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blittle/subscriptions","organizations_url":"https://api.github.com/users/blittle/orgs","repos_url":"https://api.github.com/users/blittle/repos","events_url":"https://api.github.com/users/blittle/events{/privacy}","received_events_url":"https://api.github.com/users/blittle/received_events","type":"User","site_admin":false},"created_at":"2015-11-05T18:44:31Z","updated_at":"2015-11-05T18:44:31Z","body":"@brycekahle okay, implemented it that way. Thanks!"}}