Classification system that groups HTTP status codes by their first digit, providing semantic meaning and class information for status code categorization.
The status classes provide a semantic grouping system for HTTP status codes based on their first digit.
/**
* Status classes object providing classification for HTTP status codes
*/
interface StatusClasses {
// Class identifiers - return class names
"1xx": "Informational";
"2xx": "Successful";
"3xx": "Redirection";
"4xx": "Client Error";
"5xx": "Server Error";
// Class name constants - return class identifiers
INFORMATIONAL: "1xx";
SUCCESSFUL: "2xx";
REDIRECTION: "3xx";
CLIENT_ERROR: "4xx";
SERVER_ERROR: "5xx";
// Class names - return uppercase constant names
"1xx_NAME": "INFORMATIONAL";
"2xx_NAME": "SUCCESSFUL";
"3xx_NAME": "REDIRECTION";
"4xx_NAME": "CLIENT_ERROR";
"5xx_NAME": "SERVER_ERROR";
// Class messages - return descriptive messages
"1xx_MESSAGE": "Indicates an interim response for communicating connection status or request progress prior to completing the requested action and sending a final response.";
"2xx_MESSAGE": "Indicates that the client's request was successfully received, understood, and accepted.";
"3xx_MESSAGE": "Indicates that further action needs to be taken by the user agent in order to fulfill the request.";
"4xx_MESSAGE": "Indicates that the client seems to have erred.";
"5xx_MESSAGE": "Indicates that the server is aware that it has erred or is incapable of performing the requested method.";
}Usage Examples:
import status from "http-status";
// Access class information
console.log(status.classes["2xx"]); // "Successful"
console.log(status.classes.SUCCESSFUL); // "2xx"
console.log(status.classes["2xx_NAME"]); // "SUCCESSFUL"
console.log(status.classes["2xx_MESSAGE"]); // "Indicates that the client's request was successfully received..."
// Use in switch statements for status code classification
const responseCode = 404;
const statusClass = status[`${responseCode}_CLASS`];
switch (statusClass) {
case status.classes.INFORMATIONAL:
console.log("Informational response");
break;
case status.classes.SUCCESSFUL:
console.log("Success");
break;
case status.classes.REDIRECTION:
console.log("Redirection required");
break;
case status.classes.CLIENT_ERROR:
console.log("Client error");
break;
case status.classes.SERVER_ERROR:
console.log("Server error");
break;
}The 1xx class indicates an interim response for communicating connection status or request progress.
interface InformationalClass {
"1xx": "Informational";
INFORMATIONAL: "1xx";
"1xx_NAME": "INFORMATIONAL";
"1xx_MESSAGE": "Indicates an interim response for communicating connection status or request progress prior to completing the requested action and sending a final response.";
}Examples:
100 Continue101 Switching Protocols102 Processing103 Early HintsThe 2xx class indicates that the client's request was successfully received, understood, and accepted.
interface SuccessfulClass {
"2xx": "Successful";
SUCCESSFUL: "2xx";
"2xx_NAME": "SUCCESSFUL";
"2xx_MESSAGE": "Indicates that the client's request was successfully received, understood, and accepted.";
}Examples:
200 OK201 Created202 Accepted204 No ContentThe 3xx class indicates that further action needs to be taken by the user agent to fulfill the request.
interface RedirectionClass {
"3xx": "Redirection";
REDIRECTION: "3xx";
"3xx_NAME": "REDIRECTION";
"3xx_MESSAGE": "Indicates that further action needs to be taken by the user agent in order to fulfill the request.";
}Examples:
301 Moved Permanently302 Found304 Not Modified307 Temporary RedirectThe 4xx class indicates that the client seems to have erred.
interface ClientErrorClass {
"4xx": "Client Error";
CLIENT_ERROR: "4xx";
"4xx_NAME": "CLIENT_ERROR";
"4xx_MESSAGE": "Indicates that the client seems to have erred.";
}Examples:
400 Bad Request401 Unauthorized403 Forbidden404 Not Found418 I'm a teapotThe 5xx class indicates that the server is aware that it has erred or is incapable of performing the requested method.
interface ServerErrorClass {
"5xx": "Server Error";
SERVER_ERROR: "5xx";
"5xx_NAME": "SERVER_ERROR";
"5xx_MESSAGE": "Indicates that the server is aware that it has erred or is incapable of performing the requested method.";
}Examples:
500 Internal Server Error501 Not Implemented502 Bad Gateway503 Service Unavailable504 Gateway Timeout