UNPKG

@beignet/core

Version:

Core framework primitives for Beignet

91 lines (87 loc) 1.96 kB
/** * Standard HTTP error catalog * * A base catalog of common HTTP-related errors that apps can reuse and extend. */ import { defineErrors } from "./catalog.js"; /** * A base catalog of common HTTP-related errors. * * Apps can spread this into their own error catalog: * * @example * ```ts * import { defineErrors } from "@beignet/core/errors"; * import { httpErrors } from "@beignet/core/errors/http"; * * export const errors = defineErrors({ * ...httpErrors, * TodoNotFound: { * code: "TODO_NOT_FOUND", * status: 404, * message: "Todo not found", * }, * }); * ``` */ export const httpErrors = defineErrors({ BadRequest: { code: "BAD_REQUEST", status: 400, message: "Bad request", }, Unauthorized: { code: "UNAUTHORIZED", status: 401, message: "Unauthorized", }, Forbidden: { code: "FORBIDDEN", status: 403, message: "Forbidden", }, NotFound: { code: "NOT_FOUND", status: 404, message: "Resource not found", }, Conflict: { code: "CONFLICT", status: 409, message: "Conflict", }, IdempotencyConflict: { code: "IDEMPOTENCY_CONFLICT", status: 409, message: "Idempotency key was already used with a different request", }, IdempotencyInProgress: { code: "IDEMPOTENCY_IN_PROGRESS", status: 409, message: "Idempotency key is already being processed", }, TooManyRequests: { code: "TOO_MANY_REQUESTS", status: 429, message: "Too many requests", }, UnprocessableEntity: { code: "UNPROCESSABLE_ENTITY", status: 422, message: "Unprocessable entity", }, ValidationError: { code: "VALIDATION_ERROR", status: 422, message: "Validation failed", }, InternalServerError: { code: "INTERNAL_SERVER_ERROR", status: 500, message: "Internal server error", }, }); /** * Type of the default HTTP error catalog. */ export type HttpErrorCatalog = typeof httpErrors;