API REFERENCE

Errors

import { HttpError, NotFoundError, MethodNotAllowedError, InternalServerError, } from '@rasenganjs/futon';

A small HTTP-status-bearing error hierarchy. See Error Handling for how these interact with app.onError() and app.notFound().

HttpError

class HttpError extends Error { status: number; constructor(status: number, message?: string); }

Base class. message defaults to a standard reason phrase for the given status (e.g. 404"Not Found") when omitted, falling back to "Unknown Error" for unrecognized codes.

Built-in Subclasses

class NotFoundError extends HttpError { constructor(message?: string); // status 404, default "Not Found" } class MethodNotAllowedError extends HttpError { constructor(message?: string); // status 405, default "Method Not Allowed" } class InternalServerError extends HttpError { constructor(message?: string); // status 500, default "Internal Server Error" }
ClassStatusDefault message
NotFoundError404"Not Found"
MethodNotAllowedError405"Method Not Allowed"
InternalServerError500"Internal Server Error"
Mapping HttpError to a response
import { json, HttpError } from '@rasenganjs/futon'; app.onError(async (error, ctx) => { if (error instanceof HttpError) { return json({ error: error.message }, { status: error.status }); } return json({ error: 'Internal Server Error' }, { status: 500 }); });
Hooks