elbywan / wretch

A tiny wrapper built around fetch with an intuitive syntax. :candy:
MIT License
4.83k stars 98 forks source link

Disable Error Logs in Console #65

Closed fritzfr closed 4 years ago

fritzfr commented 4 years ago

Hey,

I'm using wretch to make HEAD requests in order to determine if a resource exists or not. Based on the returned status/error, I am displaying something to the user. However, I'd like wretch to not console log it's 404 in those cases. I've tried wrapping a try/catch around the call, and also using the provided callbacks, but the error gets console logged regardless.

This is what I'd like to disable to be logged: image

Any ideas?

resourceDoesNotExist(url) {
    return api
        .url(url)
        .head()
        /* The next 3 lines are probably all the same */
        .notFound(() => true)
        .error(404, () => true)
        .res((response) => {
            if (/4\d\d/.test(response.status) === true) {
                return true;
            }

            return false;
        });
},
elbywan commented 4 years ago

Hi @felix-voicehub,

I don't think that it's related to wretch. Chrome prints when a response has an http code >= 400 by default.

You can disable these logs by unticking the Hide network checkbox:

Capture d’écran 2019-12-20 à 21 11 26