Search code examples
javascriptangularhttp-status-code-400

how to catch 400 bad request error in HTTP response in angular2


I try to catch error 400 bad request like this:

catch((error: any) => {
    if (error.status === 500) {
        return Observable.throw(new Error(error.status));
    }
    else if (error.status === 400) {
        console.log( 'error' );
        return Observable.throw(new Error(error.status));
    }

but it still appears like this in the console: enter image description here

Do you have any idea how to fix this problem or remove this message on console?

Thanks a lot.


Solution

  • This is the browser's standard behavior and cannot be influenced by you or Angular.

    If you get those messages a lot and it clutters your console whilst developing, you can filter the console. This is how you would do it in Chrome: filter network errors in chrome

    see also https://stackoverflow.com/a/14427545/4694994