Search code examples
javascriptjqueryhttphttp-status-codes

How can I convert numeric HTTP status code to its display name in javascript?


Is there a way of converting numeric http status codes (i.e. 404,403,500,...) to their display names (Not Found, Forbidden, Internal Server Error,...) ?

If it helps anything, I am using AngularJS and jQuery.


Solution

  • You could construct your own object (or download this one) and look them up there:

    var codes = {
        "100": "Continue",
        "101": "Switching Protocols",
        "102": "Processing",
        "200": "OK",
        ...
    };
    
    var code = 200;
    
    console.log(codes[code]); // "Ok"