Hide http status code warning at chrome developer console - javascript

So, I have a rest api developed in Express. For authentication, I'm using cookies and to fetch user info I just do a get request to an endpoint that return me user info if its logged in or a 401 (Unauthorized) status code if its not. My concern is about, when I get a 401 status code, the chrome developer console print
Failed to load resource: the server responded with a status of 401
(Unauthorized)
It does not cause any bug in the client, just that It bothers me to see it hah.

Create an interceptor in the HTTP requests and upon received response, use the single line code console.clear(); to clear the console output.
In that way, even if you receive 401 or 403 or any response from server and a console error/warning is auto generated, then it will be auto cleared as well!

Related

Axios shows status code of 0 instead of 403

I've been trying to capture the response of requests through axios response interceptors.
I have a request that requires authorization; and when the authorization token is valid, the request executes successfully and returns the data with no issues.
However, when the token is expired and the server/backend responds with 403; the Network tab in DevTools shows a 403 and axios shows a 0 status code with CORS issue in the Console.
I know it's not CORS because I have a wildcard allowance on it, the request works fine when the token is valid, and the pre-flight for this returns 200.
Screenshots:
Network Tab
Console Tab
This is a bug with AWS Chalice's local environment. You might be using something else that suffers from this. Here's the issue:
With the first request (options), they add access-control-allow-origin, but when the second request fails, they forget to add the header access-control-allow-origin, so it ends up in this awkward situation.
So, it's a CORS issue, but it's confusing because one has it and another doesn't.

Display http pre-flight errors in javascript

I would like to display error details on a page for errors that produce no request.responseText value. Is there some other location this information is stored?
Chrome network tab shows it as following and some other things:
(failed) net::ERR_FAILED

the apps suddenly freeze after getting the response from server

I tried to get a response from the server using axios, but then my web application froze instantly when the response was received by the client side
i got the error like this in my console
Failed to register/update a ServiceWorker for scope
‘http://localhost:3000/’: Load failed with status 404 for script
‘http://localhost:3000/sw.js’.

400 Error with Javascript Rdio API

Any thoughts on why I'm getting a "Failed to load resource: the server responded with a status of 400 (Bad Request)" in the Javascript on my client? (client-id obscured, I have one for an Oauth2.0 app via registration Rdio site)
index.html:
<script src="https://www.rdio.com/api/api.js?client_id=12345678"></script>
response:
https://www.rdio.com/oauth2/authorize/auto?response_type=token&client_id=12345678&showSignup=true&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Fhelper.html%3Fclient_id%3D12345678
Failed to load resource: the server responded with a status of 400 (Bad Request)
John
The response text from the https://www.rdio.com/oauth2/authorize/auto request should reveal the error. For example, making a request from the shell:
$ curl "https://www.rdio.com/oauth2/authorize/auto?response_type=token&client_id=12345678&showSignup=true&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Fhelper.html%3Fclient_id%3D1234567"
For a valid client ID, a possible response might be:
Invalid redirect_uri
If this is the error you're receiving, which seems likely, to resolve it, you need to add your redirect_uri's domain to the Redirect URIs in your Rdio application's settings.

Handling unsuccessful websocket upgrade requests in Javascript Client

I want to have a javascript client process get the HTTP status code that a server is returning when the client makes a websocket upgrade request and that request is unsuccessful.
I have my server returning HTTP 400 to indicate that a websocket upgrade is unsuccessful.
I am using Google Chrome and when i open the developer console I can see the following message:
WebSocket connection to 'wss://' failed: Error during WebSocket handshake: Unexpected response code: 400
However, the onerror handler does not contain this message, it receives a 1006 error but does not indicate that the closure occured as a result of getting HTTP 400.
How does a javascript developer handle handshake errors? I would like to provide the client with an informative message when they get a handshake error.
I have put the websocket error below, it does not seem to contain anything that I can use to indicate that this error is a result of a websocket handshake error.
Websocket Error: {"path":{"length":0},"cancelBubble":false,"returnValue":true,"srcElement":{"binaryType":"blob","protocol":"","extensions":"","bufferedAmount":0,"readyState":3,"url":"wss://<my address>","URL":"wss://<my address>"},"defaultPrevented":false,"timeStamp":1417828938039,"cancelable":false,"bubbles":false,"eventPhase":2,"currentTarget":{"binaryType":"blob","protocol":"","extensions":"","bufferedAmount":0,"readyState":3,"url":"wss://<my address>","URL":"wss://<my address>"},"target":{"binaryType":"blob","protocol":"","extensions":"","bufferedAmount":0,"readyState":3,"url":"wss://<my address>","URL":"wss://<my address>"},"type":"error"}
I am afraid there is no way from Javascript to know the HTTP status code of the negotiation.
There are defined closing codes, and 1006 only means that the connection is closed abruptly, but the protocol even allows to close the connection without providing a reason. That, together with the readyState API, are the only tools you have to diagnosed the reason of the problem.

Categories

Resources