Skip to main content
The StatusFlowCodes constant provides a frozen object containing all available HTTP status codes as named constants. This allows you to use semantic names instead of numeric codes.

Object Type

const StatusFlowCodes: Readonly<Record<string, number>>

Description

StatusFlowCodes is a frozen (immutable) object that maps HTTP status code names to their numeric values. The names are derived from the English names of the status codes, converted to uppercase with spaces replaced by underscores.

Generation Mechanism

The constant is generated from the status code database using this transformation:
  1. Take the English name of each status code (e.g., “Not Found”)
  2. Convert to uppercase
  3. Replace spaces with underscores
  4. Map to the numeric code
Example transformation:
  • “Not Found” → NOT_FOUND: 404
  • “Internal Server Error” → INTERNAL_SERVER_ERROR: 500
  • “Bad Request” → BAD_REQUEST: 400

Available Status Codes

Informational (1xx)

CONTINUE
number
default:"100"
Standard HTTP informational code.
SWITCHING_PROTOCOLS
number
default:"101"
Indicates protocol switching.
PROCESSING
number
default:"102"
Request is being processed.
EARLY_HINTS
number
default:"103"
Early hints before final response.

Success (2xx)

OK
number
default:"200"
Standard success response.
CREATED
number
default:"201"
Resource successfully created.
ACCEPTED
number
default:"202"
Request accepted for processing.
NON-AUTHORITATIVE_INFORMATION
number
default:"203"
Non-authoritative information.
NO_CONTENT
number
default:"204"
Successful request with no content.
RESET_CONTENT
number
default:"205"
Reset content.
PARTIAL_CONTENT
number
default:"206"
Partial content response.
MULTI-STATUS
number
default:"207"
Multiple status responses.
ALREADY_REPORTED
number
default:"208"
Already reported.
IM_USED
number
default:"226"
IM used.

Redirection (3xx)

MULTIPLE_CHOICES
number
default:"300"
Multiple choices available.
MOVED_PERMANENTLY
number
default:"301"
Resource moved permanently.
FOUND
number
default:"302"
Resource found at different URI.
SEE_OTHER
number
default:"303"
See other resource.
NOT_MODIFIED
number
default:"304"
Resource not modified.
TEMPORARY_REDIRECT
number
default:"307"
Temporary redirect.
PERMANENT_REDIRECT
number
default:"308"
Permanent redirect.

Client Errors (4xx)

BAD_REQUEST
number
default:"400"
Invalid request syntax.
UNAUTHORIZED
number
default:"401"
Authentication required.
PAYMENT_REQUIRED
number
default:"402"
Payment required.
FORBIDDEN
number
default:"403"
Access forbidden.
NOT_FOUND
number
default:"404"
Resource not found.
METHOD_NOT_ALLOWED
number
default:"405"
HTTP method not allowed.
NOT_ACCEPTABLE
number
default:"406"
Not acceptable.
REQUEST_TIMEOUT
number
default:"408"
Request timeout.
CONFLICT
number
default:"409"
Request conflicts with current state.
GONE
number
default:"410"
Resource permanently gone.
UNPROCESSABLE_CONTENT
number
default:"422"
Request cannot be processed.
TOO_MANY_REQUESTS
number
default:"429"
Rate limit exceeded.

Server Errors (5xx)

INTERNAL_SERVER_ERROR
number
default:"500"
Internal server error.
NOT_IMPLEMENTED
number
default:"501"
Functionality not implemented.
BAD_GATEWAY
number
default:"502"
Invalid gateway response.
SERVICE_UNAVAILABLE
number
default:"503"
Service temporarily unavailable.
GATEWAY_TIMEOUT
number
default:"504"
Gateway timeout.

Examples

Using Named Constants

import { StatusFlow, StatusFlowCodes } from 'status-flow';

// Instead of using magic numbers
const response = StatusFlow({ code: StatusFlowCodes.NOT_FOUND });

// More readable than
const response2 = StatusFlow({ code: 404 });

In Express Routes

import { StatusFlowCodes } from 'status-flow';
import express from 'express';

const app = express();

app.get('/users/:id', async (req, res) => {
  const user = await findUser(req.params.id);
  
  if (!user) {
    return res.status(StatusFlowCodes.NOT_FOUND).json({
      success: false,
      message: 'User not found'
    });
  }
  
  res.status(StatusFlowCodes.OK).json({
    success: true,
    data: user
  });
});

With HTTP Exceptions

import { StatusFlowCodes, NotFoundException } from 'status-flow';

function getUser(id: string) {
  const user = database.find(id);
  
  if (!user) {
    // Using the constant for consistency
    throw new NotFoundException('User not found');
  }
  
  return user;
}

// The exception will use status 404, same as StatusFlowCodes.NOT_FOUND

Validation Example

import { StatusFlowCodes } from 'status-flow';

function validateStatusCode(code: number): boolean {
  return Object.values(StatusFlowCodes).includes(code);
}

console.log(validateStatusCode(200)); // true
console.log(validateStatusCode(999)); // false

Getting All Available Codes

import { StatusFlowCodes } from 'status-flow';

// List all available status codes
const allCodes = Object.entries(StatusFlowCodes);
console.log(allCodes);

// Output:
// [
//   ['CONTINUE', 100],
//   ['OK', 200],
//   ['NOT_FOUND', 404],
//   ['INTERNAL_SERVER_ERROR', 500],
//   ...
// ]

Benefits

  • Type Safety: Avoid typos in status codes
  • Readability: Code is self-documenting
  • Maintainability: Easy to update if status codes change
  • Consistency: Use the same naming convention across your codebase
  • IDE Support: Autocomplete and IntelliSense work with named constants

Immutability

The object is frozen using Object.freeze(), making it immutable:
// This will NOT work
StatusFlowCodes.CUSTOM_CODE = 999; // Error: Cannot add property
StatusFlowCodes.OK = 201; // Error: Cannot modify property

Build docs developers (and LLMs) love