Show no 401 (Unauthorized) error on console

Asked

Viewed 351 times

0

I created a api using the passport do laravel 5.3. It works as follows: O angular 2 send credentials to the laravel, the verification and the laravel returns a token. It’s all working round.

Something that is making me unhappy is when credentials are not properly informed. Browser throws an error on the console. I am already treating such error and presenting to the user. But I wish this error did not appear on the console. see:

inserir a descrição da imagem aqui

The mistake is:

POST http://www.back.com.br/oauth/token 401 (Unauthorized)

I googled it and from what I saw some people say it has nothing to do with angular 2. That would be related to laravel.

Anyway... does anyone have an idea how to remove this error? I find it ungainly.

1 answer

1

When your API returns 401 status (Unauthorized), who handles the red error in the console is the browser and not your application itself, so there is no way not to show. Other than that, everything is probably working according to what it should, IE, probably the response variables (body) is coming from the server correctly, right?

If you want to avoid from the console showing this error, you will need to choose another status code to be returned by the API. A code that is not automatically sent as an error to the console by the browser.

If I were you, I’d leave it the way it is, because it’s good practice to follow the return codes correctly, and from what I saw in the screenshot, you’re using it at the right time. since the error "401 unauthorized" is a correct code for authentication not performed successfully.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.