@kuroson/cse-errors
v0.1.0
Published
Common error classes for TypeScript/Node.js applications
Readme
@kuroson/cse-errors
Common error classes for TypeScript/Node.js applications.
Installation
npm install @kuroson/cse-errors
# or
pnpm add @kuroson/cse-errors
# or
yarn add @kuroson/cse-errorsUsage
import { InputError, RuntimeError, SettingsError, HTTPError, parseError } from "@kuroson/cse-errors";
// Input validation errors
throw new InputError("Invalid email format");
// Runtime errors
throw new RuntimeError("Database connection failed");
// Configuration/settings errors
throw new SettingsError("Missing required environment variable");
// HTTP errors with status codes
throw new HTTPError(404, "Resource not found");
throw new HTTPError(500, "Internal server error", originalError);API
InputError
Error class for input validation failures.
new InputError(message: string, options?: ErrorOptions)RuntimeError
Error class for runtime failures.
new RuntimeError(message: string, options?: ErrorOptions)SettingsError
Error class for configuration/settings issues.
new SettingsError(message: string, options?: ErrorOptions)HTTPError
Error class for HTTP-related errors with status codes.
new HTTPError(status: number, message: string, originalError?: any)Methods:
getStatusCode(): Returns the HTTP status codegetMessage(): Returns the error message
Properties:
status: The HTTP status codemessage: The error messageoriginalError: The original error (if provided)
parseError
Utility function to safely convert any error to a string.
parseError(err: unknown): stringtry {
// some operation
} catch (err) {
console.error(parseError(err));
}Requirements
- Node.js >= 22
License
MIT
