Kind: Type
Source: src/utils/http-status.ts
Part of: Utils
If you want to use an unofficial status, use UnofficialStatusCode.
StatusCode represents the set of supported official HTTP status codes in the HTTP utilities module. Use it when APIs accept or return standard status values; use UnofficialStatusCode when an unofficial status is required.
Definition
ts| InfoStatusCode | SuccessStatusCode | RedirectStatusCode | ClientErrorStatusCode | ServerErrorStatusCode | UnofficialStatusCode
Diagram
mermaidgraph LR Response[HTTP response] --> StatusCode[StatusCode] StatusCode --> Official[Official HTTP status] Unofficial[Unofficial status] --> UnofficialStatusCode[UnofficialStatusCode]
Usage
tsimport type { StatusCode } from "./utils/http-status";
function setResponseStatus(status: StatusCode) {
return { status };
}
declare const statusFromHandler: StatusCode;
const response = setResponseStatus(statusFromHandler);
AI Coding Instructions
- Use
StatusCodefor standard HTTP status values exposed by handlers, responses, and middleware. - Use
UnofficialStatusCodeinstead of wideningStatusCodewhen working with an unofficial status. - Keep status-related function parameters typed as
StatusCodewhen unofficial values are not supported. - Treat
StatusCodeas a type-only constraint; perform runtime validation at input boundaries when status values come from external data.
Was this page helpful?