This is the HTTP Server Error Codes helper object I use in NodeJS projects.
export const const HTTP_SERVER_ERROR_CODES: { readonly BAD_REQUEST: { readonly statusCode: 400; readonly statusText: "Bad Request"; readonly message: "The request could not be understood by the server. Please check your input."; }; readonly UNAUTHORIZED: { readonly statusCode: 401; readonly statusText: "Unauthorized"; readonly message: "You need to log in or provide valid credentials to access this resource."; }; readonly PAYMENT_REQUIRED: { readonly statusCode: 402; readonly statusText: "Payment Required"; readonly message: "Payment is required to access this resource."; }; readonly FORBIDDEN: { ...; }; ... 35 more ...; readonly NETWORK_AUTHENTICATION_REQUIRED: { ...; };}
HTTP_SERVER_ERROR_CODES = { type BAD_REQUEST: { readonly statusCode: 400; readonly statusText: "Bad Request"; readonly message: "The request could not be understood by the server. Please check your input.";}
BAD_REQUEST: { statusCode: number
statusCode: 400, statusText: string
statusText: "Bad Request", message: string
message: "The request could not be understood by the server. Please check your input.", }, type UNAUTHORIZED: { readonly statusCode: 401; readonly statusText: "Unauthorized"; readonly message: "You need to log in or provide valid credentials to access this resource.";}
UNAUTHORIZED: { statusCode: number
statusCode: 401, statusText: string
statusText: "Unauthorized", message: string
message: "You need to log in or provide valid credentials to access this resource.", }, type PAYMENT_REQUIRED: { readonly statusCode: 402; readonly statusText: "Payment Required"; readonly message: "Payment is required to access this resource.";}
PAYMENT_REQUIRED: { statusCode: number
statusCode: 402, statusText: string
statusText: "Payment Required", message: string
message: "Payment is required to access this resource.", }, type FORBIDDEN: { readonly statusCode: 403; readonly statusText: "Forbidden"; readonly message: "You do not have permission to access this resource.";}
FORBIDDEN: { statusCode: number
statusCode: 403, statusText: string
statusText: "Forbidden", message: string
message: "You do not have permission to access this resource.", }, type NOT_FOUND: { readonly statusCode: 404; readonly statusText: "Not Found"; readonly message: "The requested resource could not be found.";}
NOT_FOUND: { statusCode: number
statusCode: 404, statusText: string
statusText: "Not Found", message: string
message: "The requested resource could not be found.", }, type METHOD_NOT_ALLOWED: { readonly statusCode: 405; readonly statusText: "Method Not Allowed"; readonly message: "The request method is not allowed for this resource.";}
METHOD_NOT_ALLOWED: { statusCode: number
statusCode: 405, statusText: string
statusText: "Method Not Allowed", message: string
message: "The request method is not allowed for this resource.", }, type NOT_ACCEPTABLE: { readonly statusCode: 406; readonly statusText: "Not Acceptable"; readonly message: "The server cannot produce a response matching the request's criteria.";}
NOT_ACCEPTABLE: { statusCode: number
statusCode: 406, statusText: string
statusText: "Not Acceptable", message: string
message: "The server cannot produce a response matching the request's criteria.", }, type PROXY_AUTHENTICATION_REQUIRED: { readonly statusCode: 407; readonly statusText: "Proxy Authentication Required"; readonly message: "You need to authenticate with a proxy server before accessing this resource.";}
PROXY_AUTHENTICATION_REQUIRED: { statusCode: number
statusCode: 407, statusText: string
statusText: "Proxy Authentication Required", message: string
message: "You need to authenticate with a proxy server before accessing this resource.", }, type REQUEST_TIMEOUT: { readonly statusCode: 408; readonly statusText: "Request Timeout"; readonly message: "The server took too long to respond. Please try again later.";}
REQUEST_TIMEOUT: { statusCode: number
statusCode: 408, statusText: string
statusText: "Request Timeout", message: string
message: "The server took too long to respond. Please try again later.", }, type CONFLICT: { readonly statusCode: 409; readonly statusText: "Conflict"; readonly message: "There was a conflict with the current state of the resource.";}
CONFLICT: { statusCode: number
statusCode: 409, statusText: string
statusText: "Conflict", message: string
message: "There was a conflict with the current state of the resource.", }, type GONE: { readonly statusCode: 410; readonly statusText: "Gone"; readonly message: "The resource you are looking for is no longer available.";}
GONE: { statusCode: number
statusCode: 410, statusText: string
statusText: "Gone", message: string
message: "The resource you are looking for is no longer available.", }, type LENGTH_REQUIRED: { readonly statusCode: 411; readonly statusText: "Length Required"; readonly message: "The request must include a valid Content-Length header.";}
LENGTH_REQUIRED: { statusCode: number
statusCode: 411, statusText: string
statusText: "Length Required", message: string
message: "The request must include a valid Content-Length header.", }, type PRECONDITION_FAILED: { readonly statusCode: 412; readonly statusText: "Precondition Failed"; readonly message: "A precondition in the request was not met.";}
PRECONDITION_FAILED: { statusCode: number
statusCode: 412, statusText: string
statusText: "Precondition Failed", message: string
message: "A precondition in the request was not met.", }, type PAYLOAD_TOO_LARGE: { readonly statusCode: 413; readonly statusText: "Payload Too Large"; readonly message: "The request payload is too large for the server to process.";}
PAYLOAD_TOO_LARGE: { statusCode: number
statusCode: 413, statusText: string
statusText: "Payload Too Large", message: string
message: "The request payload is too large for the server to process.", }, type URI_TOO_LONG: { readonly statusCode: 414; readonly statusText: "URI Too Long"; readonly message: "The requested URL is too long for the server to handle.";}
URI_TOO_LONG: { statusCode: number
statusCode: 414, statusText: string
statusText: "URI Too Long", message: string
message: "The requested URL is too long for the server to handle.", }, type UNSUPPORTED_MEDIA_TYPE: { readonly statusCode: 415; readonly statusText: "Unsupported Media Type"; readonly message: "The server does not support the media format of the requested data.";}
UNSUPPORTED_MEDIA_TYPE: { statusCode: number
statusCode: 415, statusText: string
statusText: "Unsupported Media Type", message: string
message: "The server does not support the media format of the requested data.", }, type RANGE_NOT_SATISFIABLE: { readonly statusCode: 416; readonly statusText: "Range Not Satisfiable"; readonly message: "The requested range is not available for this resource.";}
RANGE_NOT_SATISFIABLE: { statusCode: number
statusCode: 416, statusText: string
statusText: "Range Not Satisfiable", message: string
message: "The requested range is not available for this resource.", }, type EXPECTATION_FAILED: { readonly statusCode: 417; readonly statusText: "Expectation Failed"; readonly message: "The server cannot meet the expectations given in the request headers.";}
EXPECTATION_FAILED: { statusCode: number
statusCode: 417, statusText: string
statusText: "Expectation Failed", message: string
message: "The server cannot meet the expectations given in the request headers.", }, type IM_A_TEAPOT: { readonly statusCode: 418; readonly statusText: "I'm a teapot"; readonly message: "This is a joke response. The server refuses to brew coffee.";}
IM_A_TEAPOT: { statusCode: number
statusCode: 418, statusText: string
statusText: "I'm a teapot", message: string
message: "This is a joke response. The server refuses to brew coffee.", }, type MISDIRECTED_REQUEST: { readonly statusCode: 421; readonly statusText: "Misdirected Request"; readonly message: "The request was sent to the wrong server.";}
MISDIRECTED_REQUEST: { statusCode: number
statusCode: 421, statusText: string
statusText: "Misdirected Request", message: string
message: "The request was sent to the wrong server.", }, type UNPROCESSABLE_ENTITY: { readonly statusCode: 422; readonly statusText: "Unprocessable Entity"; readonly message: "The request was well-formed but could not be processed due to semantic errors.";}
UNPROCESSABLE_ENTITY: { statusCode: number
statusCode: 422, statusText: string
statusText: "Unprocessable Entity", message: string
message: "The request was well-formed but could not be processed due to semantic errors.", }, type LOCKED: { readonly statusCode: 423; readonly statusText: "Locked"; readonly message: "The requested resource is locked and cannot be accessed.";}
LOCKED: { statusCode: number
statusCode: 423, statusText: string
statusText: "Locked", message: string
message: "The requested resource is locked and cannot be accessed.", }, type FAILED_DEPENDENCY: { readonly statusCode: 424; readonly statusText: "Failed Dependency"; readonly message: "A dependency for the request failed, so the request could not be completed.";}
FAILED_DEPENDENCY: { statusCode: number
statusCode: 424, statusText: string
statusText: "Failed Dependency", message: string
message: "A dependency for the request failed, so the request could not be completed.", }, type TOO_EARLY: { readonly statusCode: 425; readonly statusText: "Too Early"; readonly message: "The server is unwilling to process the request at this time.";}
TOO_EARLY: { statusCode: number
statusCode: 425, statusText: string
statusText: "Too Early", message: string
message: "The server is unwilling to process the request at this time.", }, type UPGRADE_REQUIRED: { readonly statusCode: 426; readonly statusText: "Upgrade Required"; readonly message: "The client must upgrade to a newer protocol version.";}
UPGRADE_REQUIRED: { statusCode: number
statusCode: 426, statusText: string
statusText: "Upgrade Required", message: string
message: "The client must upgrade to a newer protocol version.", }, type PRECONDITION_REQUIRED: { readonly statusCode: 428; readonly statusText: "Precondition Required"; readonly message: "The request requires certain conditions to be met before proceeding.";}
PRECONDITION_REQUIRED: { statusCode: number
statusCode: 428, statusText: string
statusText: "Precondition Required", message: string
message: "The request requires certain conditions to be met before proceeding.", }, type TOO_MANY_REQUESTS: { readonly statusCode: 429; readonly statusText: "Too Many Requests"; readonly message: "You have made too many requests in a short period. Please slow down.";}
TOO_MANY_REQUESTS: { statusCode: number
statusCode: 429, statusText: string
statusText: "Too Many Requests", message: string
message: "You have made too many requests in a short period. Please slow down.", }, type REQUEST_HEADER_FIELDS_TOO_LARGE: { readonly statusCode: 431; readonly statusText: "Request Header Fields Too Large"; readonly message: "The request headers are too large for the server to process.";}
REQUEST_HEADER_FIELDS_TOO_LARGE: { statusCode: number
statusCode: 431, statusText: string
statusText: "Request Header Fields Too Large", message: string
message: "The request headers are too large for the server to process.", }, type UNAVAILABLE_FOR_LEGAL_REASONS: { readonly statusCode: 451; readonly statusText: "Unavailable For Legal Reasons"; readonly message: "Access to this resource has been restricted for legal reasons.";}
UNAVAILABLE_FOR_LEGAL_REASONS: { statusCode: number
statusCode: 451, statusText: string
statusText: "Unavailable For Legal Reasons", message: string
message: "Access to this resource has been restricted for legal reasons.", }, type INTERNAL_SERVER_ERROR: { readonly statusCode: 500; readonly statusText: "Internal Server Error"; readonly message: "Something went wrong on our end. Please try again later.";}
INTERNAL_SERVER_ERROR: { statusCode: number
statusCode: 500, statusText: string
statusText: "Internal Server Error", message: string
message: "Something went wrong on our end. Please try again later.", }, type NOT_IMPLEMENTED: { readonly statusCode: 501; readonly statusText: "Not Implemented"; readonly message: "This request method is not supported by the server.";}
NOT_IMPLEMENTED: { statusCode: number
statusCode: 501, statusText: string
statusText: "Not Implemented", message: string
message: "This request method is not supported by the server.", }, type BAD_GATEWAY: { readonly statusCode: 502; readonly statusText: "Bad Gateway"; readonly message: "The server received an invalid response from an upstream server.";}
BAD_GATEWAY: { statusCode: number
statusCode: 502, statusText: string
statusText: "Bad Gateway", message: string
message: "The server received an invalid response from an upstream server.", }, type SERVICE_UNAVAILABLE: { readonly statusCode: 503; readonly statusText: "Service Unavailable"; readonly message: "The server is temporarily unavailable. Please try again later.";}
SERVICE_UNAVAILABLE: { statusCode: number
statusCode: 503, statusText: string
statusText: "Service Unavailable", message: string
message: "The server is temporarily unavailable. Please try again later.", }, type GATEWAY_TIMEOUT: { readonly statusCode: 504; readonly statusText: "Gateway Timeout"; readonly message: "The server took too long to respond. Please try again later.";}
GATEWAY_TIMEOUT: { statusCode: number
statusCode: 504, statusText: string
statusText: "Gateway Timeout", message: string
message: "The server took too long to respond. Please try again later.", }, type HTTP_VERSION_NOT_SUPPORTED: { readonly statusCode: 505; readonly statusText: "HTTP Version Not Supported"; readonly message: "The server does not support the HTTP version used in the request.";}
HTTP_VERSION_NOT_SUPPORTED: { statusCode: number
statusCode: 505, statusText: string
statusText: "HTTP Version Not Supported", message: string
message: "The server does not support the HTTP version used in the request.", }, type VARIANT_ALSO_NEGOTIATES: { readonly statusCode: 506; readonly statusText: "Variant Also Negotiates"; readonly message: "There was an internal configuration error while processing your request.";}
VARIANT_ALSO_NEGOTIATES: { statusCode: number
statusCode: 506, statusText: string
statusText: "Variant Also Negotiates", message: string
message: "There was an internal configuration error while processing your request.", }, type INSUFFICIENT_STORAGE: { readonly statusCode: 507; readonly statusText: "Insufficient Storage"; readonly message: "The server has run out of storage space to complete the request.";}
INSUFFICIENT_STORAGE: { statusCode: number
statusCode: 507, statusText: string
statusText: "Insufficient Storage", message: string
message: "The server has run out of storage space to complete the request.", }, type LOOP_DETECTED: { readonly statusCode: 508; readonly statusText: "Loop Detected"; readonly message: "The server detected an infinite loop while processing your request.";}
LOOP_DETECTED: { statusCode: number
statusCode: 508, statusText: string
statusText: "Loop Detected", message: string
message: "The server detected an infinite loop while processing your request.", }, type NOT_EXTENDED: { readonly statusCode: 510; readonly statusText: "Not Extended"; readonly message: "Further extensions to the request are required for it to be processed.";}
NOT_EXTENDED: { statusCode: number
statusCode: 510, statusText: string
statusText: "Not Extended", message: string
message: "Further extensions to the request are required for it to be processed.", }, type NETWORK_AUTHENTICATION_REQUIRED: { readonly statusCode: 511; readonly statusText: "Network Authentication Required"; readonly message: "You need to authenticate to access the network.";}
NETWORK_AUTHENTICATION_REQUIRED: { statusCode: number
statusCode: 511, statusText: string
statusText: "Network Authentication Required", message: string
message: "You need to authenticate to access the network.", },} as type const = { readonly BAD_REQUEST: { readonly statusCode: 400; readonly statusText: "Bad Request"; readonly message: "The request could not be understood by the server. Please check your input."; }; readonly UNAUTHORIZED: { readonly statusCode: 401; readonly statusText: "Unauthorized"; readonly message: "You need to log in or provide valid credentials to access this resource."; }; readonly PAYMENT_REQUIRED: { readonly statusCode: 402; readonly statusText: "Payment Required"; readonly message: "Payment is required to access this resource."; }; readonly FORBIDDEN: { ...; }; ... 35 more ...; readonly NETWORK_AUTHENTICATION_REQUIRED: { ...; };}
const satisfies type Record<K extends keyof any, T> = { [P in K]: T; }
Construct a type with a set of properties K of type T
Record< string, { statusCode: number
statusCode: number; statusText: string
statusText: string; message: string
message: string; }>;