Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing http status code constants

Tags:

javascript

I'm looking for a list of http status codes in Javascript. Are they defined in any implementation?

I've had a look at XMLHttpRequest, but only found readyState constants.

var xhr = new XMLHttpRequest(); console.log(xhr.DONE); //4 

I'm looking for something like

console.log(xhr.statusCodes.OK); //200 

Which obviously doesn't exist on the xhr object.

like image 889
Johan Avatar asked Sep 12 '13 13:09

Johan


People also ask

How do I retrieve my HTTP status code?

In the main window of the program, enter your website homepage URL and click on the 'Start' button. As soon as crawling is complete, you will have all status codes in the corresponding table column. Pages with the 4xx and 5xx HTTP status codes will be gathered into special issue reports.

What are status code 2xx 3xx 4xx 5xx in API?

2xx successful – the request was successfully received, understood, and accepted. 3xx redirection – further action needs to be taken in order to complete the request. 4xx client error – the request contains bad syntax or cannot be fulfilled. 5xx server error – the server failed to fulfil an apparently valid request.

Which HTTP status codes would indicate a page has been moved permanently?

The HyperText Transfer Protocol (HTTP) 301 Moved Permanently redirect status response code indicates that the requested resource has been definitively moved to the URL given by the Location headers.

What is a 309 status code?

Status codes 309 through 399 are currently unassigned.


1 Answers

For node.js you can use the module node-http-status (github).

This is an example:

var HttpStatus = require('http-status-codes');  response     .status(HttpStatus.OK)     .send('ok');  response     .status(HttpStatus.INTERNAL_SERVER_ERROR)     .send({         error: HttpStatus.getStatusText(HttpStatus.INTERNAL_SERVER_ERROR)     }); 
like image 113
mpolci Avatar answered Sep 22 '22 10:09

mpolci