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.
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.
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"
Just to help everyone to copy/paste
/* Helpers */
var friendlyHttpStatus = {
'200': 'OK',
'201': 'Created',
'202': 'Accepted',
'203': 'Non-Authoritative Information',
'204': 'No Content',
'205': 'Reset Content',
'206': 'Partial Content',
'300': 'Multiple Choices',
'301': 'Moved Permanently',
'302': 'Found',
'303': 'See Other',
'304': 'Not Modified',
'305': 'Use Proxy',
'306': 'Unused',
'307': 'Temporary Redirect',
'400': 'Bad Request',
'401': 'Unauthorized',
'402': 'Payment Required',
'403': 'Forbidden',
'404': 'Not Found',
'405': 'Method Not Allowed',
'406': 'Not Acceptable',
'407': 'Proxy Authentication Required',
'408': 'Request Timeout',
'409': 'Conflict',
'410': 'Gone',
'411': 'Length Required',
'412': 'Precondition Required',
'413': 'Request Entry Too Large',
'414': 'Request-URI Too Long',
'415': 'Unsupported Media Type',
'416': 'Requested Range Not Satisfiable',
'417': 'Expectation Failed',
'418': 'I\'m a teapot',
'429': 'Too Many Requests',
'500': 'Internal Server Error',
'501': 'Not Implemented',
'502': 'Bad Gateway',
'503': 'Service Unavailable',
'504': 'Gateway Timeout',
'505': 'HTTP Version Not Supported',
};
/* Usage */
var code = 200;
console.log(friendlyHttpStatus[code]); // "Ok"
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"
You can use http-status-codes from npm.
var HttpStatus = require('http-status-codes');
HttpStatus.getStatusText(200) // ==> "OK"
I don't think so, but you can use this useful site : http://httpstat.us/ .
My crappy solution:
var friendlyHttpStatus = function(status){
if(status == '200') return 'OK'
if(status == '201') return 'Created'
if(status == '202') return 'Accepted'
if(status == '203') return 'Non-Authoritative Information'
if(status == '204') return 'No Content'
if(status == '205') return 'Reset Content'
if(status == '206') return 'Partial Content'
if(status == '300') return 'Multiple Choices'
if(status == '301') return 'Moved Permanently'
if(status == '302') return 'Found'
if(status == '303') return 'See Other'
if(status == '304') return 'Not Modified'
if(status == '305') return 'Use Proxy'
if(status == '306') return 'Unused'
if(status == '307') return 'Temporary Redirect'
if(status == '400') return 'Bad Request'
if(status == '401') return 'Unauthorized'
if(status == '402') return 'Payment Required'
if(status == '403') return 'Forbidden'
if(status == '404') return 'Not Found'
if(status == '405') return 'Method Not Allowed'
if(status == '406') return 'Not Acceptable'
if(status == '407') return 'Proxy Authentication Required'
if(status == '408') return 'Request Timeout'
if(status == '409') return 'Conflict'
if(status == '410') return 'Gone'
if(status == '411') return 'Length Required'
if(status == '412') return 'Precondition Required'
if(status == '413') return 'Request Entry Too Large'
if(status == '414') return 'Request-URI Too Long'
if(status == '415') return 'Unsupported Media Type'
if(status == '416') return 'Requested Range Not Satisfiable'
if(status == '417') return 'Expectation Failed'
if(status == '418') return 'I\'m a teapot'
if(status == '500') return 'Internal Server Error'
if(status == '501') return 'Not Implemented'
if(status == '502') return 'Bad Gateway'
if(status == '503') return 'Service Unavailable'
if(status == '504') return 'Gateway Timeout'
if(status == '505') return 'HTTP Version Not Supported'
}
© 2022 - 2024 — McMap. All rights reserved.