Created
July 15, 2025 17:50
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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