Kind: Type
Source: src/utils/http-status.ts
Part of: Utils
UnofficialStatusCode can be used to specify an unofficial status code.
UnofficialStatusCode represents HTTP status codes that are not part of the standard status-code set. Use it when an API response or error path needs to declare an unofficial HTTP status value with type checking.
Definition
ts-1
Diagram
mermaidgraph LR Application[Application code] --> Status[UnofficialStatusCode] Status --> Response[HTTP response status]
Usage
tsimport type { UnofficialStatusCode } from './utils/http-status';
type ErrorResponse = {
statusCode: UnofficialStatusCode;
message: string;
};
const response: ErrorResponse = {
statusCode: 419,
message: 'Session expired',
};
AI Coding Instructions
- Use
UnofficialStatusCodefor response paths that return a supported unofficial HTTP status value. - Keep standard HTTP status codes typed through the corresponding standard status-code type.
- Do not cast arbitrary numbers to
UnofficialStatusCode; add a value only when it belongs in the type definition. - Preserve the type when passing status codes through response helpers and error handlers.
Was this page helpful?