Search code examples
javascriptreactjshttp-status-codes

error description from http error code - react.js/javascript


I have a Component in my react.js application, which display an error code.

Like this:

error_page_react.js

Now I'm displaying just a code, along with this what I want to to is - show the reason of this error too. Like this page contains a lot of information about error codes.

How can I do it ?

If I get any error, then I get the error code and use window.location="/bad_request/".concat(err_code);

In my ErrorPage component I've :

componentWillMount() {
    this.state.errorCode = this.props.match.params.errorCode;
    console.log(this.state.errorCode);

}

Rest is simple.


Solution

  • I wrote this to my java-script file :

    let map = new Map();
    map.set(400,'Bad Request');
    map.set(401,'Unauthorized');
    ...
    

    When I get redirected to this page, I just get what was the description of the error.

    Now I have entered all the data manually, I was just asking if there was any automated way to log these.