Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Don't log request in browser console

I want to load a user by his email address via a Restfull API.
If the user does not exist, I receive the status "404 – Not found" as a response.
In this case I return "null", because it is not an error for the application, but a defined state.

However, the request is always displayed as an error in the browser console.

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Is there any way to prevent this and not log the supposed error?

export async function getUserByEmail(email: string): Promise<User | null> {
    let result: User | null = null;

    axios.get(config.api.url + "/user/email/" + email)
        .then(res => res.data())
        .then((data) => {
            result = User.fromJson(data);
        })
        .catch((error) => {
            if (error.response.status !== 404) {
                throw new ApiError(error.response.status, error.message);
            }
        })

    return result;
}

>Solution :

When the browser console is configured to log XHR requests, you can’t suppress those logs using JS.

If you find them distracting, change your developer tools preferences to turn that option off (and use the Network tab when you want to see XHR requests).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading