2

I am building a SignIn component in ReactJS. So I have a standard Axios post request to signin a user:

try {
  // Authenticate against NodeJS
  const res = await axios.post(`${API_URL}/auth/signin`, {
    email: this.state.email,
    password: this.state.password
  });

...

} catch (err) {
  // I don't want to display anything to the client;
}

If I want to, I can successfully catch the error on an incorrect password (401 error). However in this case I do not want to display anything on the client browser's console. The problem is that Axios (even with Fetch) does not care about the catch and still displays its own XHR error:

enter image description here

Is there a way to prevent these type of errors from appearing in the console?

James
  • 3,597
  • 11
  • 41
  • 76
  • @zero298 no it's not a duplicate. Since I am handling the error in the code, I cannot understand why the error would still pop up on the client's side. This is not a question of filtering errors for my own posterity, but to prevent the error leaking to the client anyway. – James Aug 03 '18 at 17:44
  • 1
    That's the thing, even if you catch the error, it is going to appear in the console no matter what. See this question as well: [Hide 401 console.error in chrome dev tools getting 401 on fetch() call](https://stackoverflow.com/a/42986081/691711) – zero298 Aug 03 '18 at 17:48
  • thanks @zero298 the last question is actually answering my issue. – James Aug 03 '18 at 17:50

0 Answers0