Home > OS >  Is there a way to stop 401 unauthorized from logging to console?
Is there a way to stop 401 unauthorized from logging to console?

Time:01-11

I have a function in Vue.js which sends data to the back-end to log the user in. However in cases where the User doesnt exist it returns an 401 unauthorized. That is ok by me , the problem is that it always seems to be logged into the console. I already know i can handle it but it always logs to the console. Is there a way to stop the web console from logging the 401 unauthorized ?

My function

  this.$store
          .dispatch("userLogin", {
            username: this.username,
            password: this.password,
          })
          .then((response) => {
            switch (response.status) {
              case 401:
                //I know unauthorized attempt can be handled here.
                break;
            }
            this.$router.push({ name: "Admin" });
          })
          .catch(function (error) {
            console.log(error.response.data);
          });
      }

I want to stop this from being logged.

https://ibb.co/6vNdYrw

CodePudding user response:

You can't do that. It's the same as trying to stop requests from showing up in Chrome's Network Tab. It's implemented by the browser and the website does not have control over it.

CodePudding user response:

You cannot really block logging responses from requests into browser console.

In your case you have such a flow, that server responds with code 401 when you are sending invalid user details. It should obviously respond with 404 but probably you do not have any control over it.

The solution to this could be to have function, that would evaluate both response.status and response.data and based on response.data process your case further.

Some initial solution:

switch (response.data && response.status) {
  case ('not found' && 401):
    // handle case
    break;

  default:
    break;
 }
       
  •  Tags:  
  • Related