Do not display 401 (Unauthorized) error in console

0

I created a api using passport do laravel 5.3 . It works as follows: angular 2 sends credentials to laravel , verification is performed, laravel returns token . It's all working round.

Something that is making me unhappy is when the credentials are not properly entered. Browser throws an error in the console. I'm already handling such a bug and introducing it to the user. But I wanted this error not to appear on the console. see:

Theerroris:

  

POST link 401 (Unauthorized)

I gave a search in google and from what I saw some people talking it has nothing to do with angular 2 . This would be related to laravel .

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

    
asked by anonymous 01.10.2016 / 23:00

1 answer

0

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

If you want to prevent the console from displaying this error, you will have 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 would leave it as it is, because it is good practice to correctly follow return codes, and from what I saw in the screenshot, you are using it at the right time. since the "401 Unauthorized" error is a correct code for authentication not performed successfully.

    
03.10.2016 / 21:06