Skip to content

@jaypie/errors

Error class definitions for Jaypie applications.

@jaypie/errors provides a comprehensive set of error classes for common HTTP status codes and application errors:

  • HTTP error classes (400, 401, 403, 404, 500, etc.)
  • Base JaypieError class
  • Error factory functions
  • JSON:API error formatting
Terminal window
npm install @jaypie/errors

Pre-defined error classes for common HTTP status codes:

import {
BadRequestError,
UnauthorizedError,
ForbiddenError,
NotFoundError,
InternalError,
} from "@jaypie/errors";
throw new BadRequestError("Invalid input");
throw new NotFoundError("User not found");
throw new InternalError("Database connection failed");

All errors extend the base JaypieError class, which includes:

  • statusCode - HTTP status code
  • message - Error message
  • JSON:API formatting
  • Logging integration

Create custom errors with specific status codes:

import { errorFactory } from "@jaypie/errors";
const CustomError = errorFactory(418, "I'm a teapot");
throw new CustomError("Cannot brew coffee");

API documentation will be generated from TypeScript definitions.