Skip to content

HttpStatusCodes — status code constants

Imported from the facade: import { HttpStatusCodes } from "@/framework/facade.js".

Numeric HTTP status constants (from stoker) used in createRoute responses and c.json(...) calls. See OpenAPI.

Signature

FunctionSignatureDescription
HttpStatusCodesconstNumeric HTTP status code constants

Common values:

ConstantValueConstantValue
HttpStatusCodes.OK200HttpStatusCodes.NOT_FOUND404
HttpStatusCodes.CREATED201HttpStatusCodes.INTERNAL_SERVER_ERROR500
HttpStatusCodes.UNAUTHORIZED401HttpStatusCodes.UNPROCESSABLE_ENTITY422
HttpStatusCodes.FORBIDDEN403HttpStatusCodes.TOO_MANY_REQUESTS429

Use cases

Route responses

ts
createRoute({
  path: "/login",
  method: "post",
  tags: ["Auth"],
  responses: { [HttpStatusCodes.OK]: jsonContent(AuthResponseSchema, "Logged in") },
});

Real world — controller responses

ts
if (!user || !(await password.verifyPassword(body.password, user.password))) {
  return c.json({ message: "Invalid credentials" }, HttpStatusCodes.UNAUTHORIZED);
}
if (authConfig.requireEmailVerification && !user.emailVerifiedAt) {
  return c.json({ message: "Please verify your email before logging in" }, HttpStatusCodes.FORBIDDEN);
}
return c.json({ message: "User logged in successfully", data }, HttpStatusCodes.OK);

Notes

  • Keys must match OpenAPI numeric keys for createRoute responses.
  • The full stoker/http-status-codes export is re-exported — every status name is available.

Released under the MIT License.