Skip to content

Built-in Errors

All framework errors in Volten extend the base class VoltenError.

The VoltenError Base Class

VoltenError extends the JavaScript native Error and attaches structured HTTP metadata:

typescript
export class VoltenError extends Error {
  public readonly code: string; // e.g. 'ERR_NOT_FOUND'
  public readonly statusCode: number; // e.g. 404

  constructor(code: string, message: string, statusCode: number = 500, options?: ErrorOptions);

  public static from(error: unknown): VoltenError;
  public static isVoltenError(error: unknown): error is VoltenError;
  public toJSON(includeStack?: boolean): { error: object };
}

Key Utilities

  • VoltenError.from(err): Converts any unknown value (e.g. a string or a third-party Error) into a VoltenError while preserving the original stack trace.
  • VoltenError.isVoltenError(err): A TypeScript type guard to test if an unknown error originates from Volten.
  • err.toJSON(includeStack?): Formats the error into a structured JSON payload suitable for API responses.

Built-in Error Reference

Class NameStatusCodeDescription
NotFoundError404ERR_NOT_FOUNDThrown when a requested route or static file does not exist.
MethodNotAllowedError405ERR_METHOD_NOT_ALLOWEDThrown when the path exists, but the HTTP method is not registered. Contains allowedMethods.
PayloadTooLargeError413ERR_PAYLOAD_TOO_LARGEThrown when request body exceeds the configured bodyLimit.
BadRequestError400ERR_BAD_REQUESTGeneral bad request / client-side input error.
BodyReadOnInvalidMethodError400ERR_BODY_READ_ON_INVALID_METHODThrown if an attempt is made to read body on invalid methods.
HeadersSentError500ERR_HEADERS_SENTThrown when attempting to modify headers after they have already been flushed to the socket.
ResponseSentError500ERR_RESPONSE_SENTThrown when attempting to send a body after the response has finalized.
InvalidNextCallError500ERR_INVALID_NEXT_CALLThrown when next() is called multiple times or after the response has finished.
ServiceUnavailableError503ERR_SERVICE_UNAVAILABLEThrown when server context pools or capacity limits are reached.
DuplicateRouteError500ERR_DUPLICATE_ROUTEThrown during startup when registering duplicate HTTP method + path patterns.

Released under the MIT License.