Skip to content

StatusCode

reference
1 min readUpdated

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

mermaid
graph LR
  Response[HTTP response] --> StatusCode[StatusCode]
  StatusCode --> Official[Official HTTP status]
  Unofficial[Unofficial status] --> UnofficialStatusCode[UnofficialStatusCode]

Usage

ts
import type { StatusCode } from "./utils/http-status";

function setResponseStatus(status: StatusCode) {
  return { status };
}

declare const statusFromHandler: StatusCode;

const response = setResponseStatus(statusFromHandler);

AI Coding Instructions

  • Use StatusCode for standard HTTP status values exposed by handlers, responses, and middleware.
  • Use UnofficialStatusCode instead of widening StatusCode when working with an unofficial status.
  • Keep status-related function parameters typed as StatusCode when unofficial values are not supported.
  • Treat StatusCode as a type-only constraint; perform runtime validation at input boundaries when status values come from external data.

Was this page helpful?

Download as PDF
StatusCode — Hono (narrator proof)