Skip to content

Instantly share code, notes, and snippets.

@gameshler
Created July 15, 2025 17:50
Show Gist options
  • Select an option

  • Save gameshler/4e407cfa3d17871b26449e27302dccaf to your computer and use it in GitHub Desktop.

Select an option

Save gameshler/4e407cfa3d17871b26449e27302dccaf to your computer and use it in GitHub Desktop.
Minimal and readable HTTP status code constants with a type-safe union in TypeScript. Ideal for use in API responses, error handlers, and service layers.
export const OK = 200;
export const CREATED = 201;
export const BAD_REQUEST = 400;
export const UNAUTHORIZED = 401;
export const FORBIDDEN = 403;
export const NOT_FOUND = 404;
export const CONFLICT = 409;
export const UNPROCESSABLE_CONTENT = 422;
export const TOO_MANY_REQUESTS = 429;
export const INTERNAL_SERVER_ERROR = 500;
export type HttpStatusCode =
| typeof OK
| typeof CREATED
| typeof BAD_REQUEST
| typeof UNAUTHORIZED
| typeof FORBIDDEN
| typeof NOT_FOUND
| typeof CONFLICT
| typeof UNPROCESSABLE_CONTENT
| typeof TOO_MANY_REQUESTS
| typeof INTERNAL_SERVER_ERROR;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment