Utility to interact with HTTP status codes
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
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 Continue - Server received request headers, client should proceed101 Switching Protocols - Server agrees to switch protocols102 Processing - Server is processing the request (WebDAV)103 Early Hints - Return response headers before final HTTP messageThe 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 OK - Standard successful response201 Created - Request fulfilled, new resource created202 Accepted - Request accepted for processing204 No Content - Request processed, no content returnedThe 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 Permanently - Resource permanently moved to new URL302 Found - Resource temporarily moved304 Not Modified - Resource not modified since last request307 Temporary Redirect - Request should be repeated with another URIThe 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 Request - Malformed request syntax401 Unauthorized - Authentication required403 Forbidden - Server refuses to authorize request404 Not Found - Requested resource not found418 I'm a teapot - Easter egg status codeThe 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 Error - Generic server error501 Not Implemented - Server doesn't support the functionality502 Bad Gateway - Invalid response from upstream server503 Service Unavailable - Server temporarily unavailable504 Gateway Timeout - Upstream server timeout