ono-http

raw JSON →
0.2.0 verified Sat Apr 25 auth: no javascript

ono-http (v0.2.0) extends the ono library to create HTTP-specific error objects with status codes and standard HTTP error messages. It allows throwing errors with a status code (e.g., 404) and an optional custom message using printf-style formatting. The library is lightweight, wraps inner errors, and integrates with ono's error formatting. Current version is early (0.x) and not widely adopted; no clear release cadence. Key differentiator: combines ono's structured error throwing with HTTP status codes for server-side applications.

error TypeError: OnoHttpError is not a constructor
cause Attempting to use new OnoHttpError() directly, but it's a named export not a constructor
fix
Import { OnoHttpError } and use it as a base class: class MyError extends OnoHttpError {}
error Error: Expected a numeric HTTP status code, got "404"
cause Passing status code as string instead of number
fix
httpError(404, 'Not Found') - use integer
error Cannot find module 'ono-http'
cause Missing ono peer dependency
fix
npm install ono ono-http
breaking Package is v0.2.0 - API may change in future versions without major semver bump
fix Pin exact version in package.json
gotcha httpError expects (statusCode, message, ...args) or (statusCode, innerError) - do not mix both in one call
fix Use separate httpError calls or ono for combined messages with inner errors
deprecated createErrorClass may be removed in future versions; prefer using httpError directly
fix Use httpError(statusCode, message) for simple cases
npm install ono-http
yarn add ono-http
pnpm add ono-http

Shows how to create and throw HTTP errors with status codes and format messages, and how to wrap existing errors.

import { httpError } from 'ono-http';

// Throw a 404 Not Found error with a custom message
const err = httpError(404, 'Resource %s not found', 'user/123');
throw err;

// Wrap an existing error with HTTP status
const original = new Error('Database connection failed');
const wrapped = httpError(500, original);
throw wrapped;