{"id":18628,"library":"ono-http","title":"ono-http","description":"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.","status":"active","version":"0.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/danieljoppi/ono-http","tags":["javascript","throw","error","errors","exception","printf","format","wrap","ono"],"install":[{"cmd":"npm install ono-http","lang":"bash","label":"npm"},{"cmd":"yarn add ono-http","lang":"bash","label":"yarn"},{"cmd":"pnpm add ono-http","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core dependency for error creation and formatting","package":"ono","optional":false}],"imports":[{"note":"ESM-only package; no default export.","wrong":"const httpError = require('ono-http')","symbol":"httpError","correct":"import { httpError } from 'ono-http'"},{"note":"Used to create custom HTTP error subclasses.","wrong":null,"symbol":"createErrorClass","correct":"import { createErrorClass } from 'ono-http'"},{"note":"Named export, not default.","wrong":"import OnoHttpError from 'ono-http'","symbol":"OnoHttpError","correct":"import { OnoHttpError } from 'ono-http'"}],"quickstart":{"code":"import { httpError } from 'ono-http';\n\n// Throw a 404 Not Found error with a custom message\nconst err = httpError(404, 'Resource %s not found', 'user/123');\nthrow err;\n\n// Wrap an existing error with HTTP status\nconst original = new Error('Database connection failed');\nconst wrapped = httpError(500, original);\nthrow wrapped;","lang":"typescript","description":"Shows how to create and throw HTTP errors with status codes and format messages, and how to wrap existing errors."},"warnings":[{"fix":"Pin exact version in package.json","message":"Package is v0.2.0 - API may change in future versions without major semver bump","severity":"breaking","affected_versions":">=0.0.0"},{"fix":"Use separate httpError calls or ono for combined messages with inner errors","message":"httpError expects (statusCode, message, ...args) or (statusCode, innerError) - do not mix both in one call","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use httpError(statusCode, message) for simple cases","message":"createErrorClass may be removed in future versions; prefer using httpError directly","severity":"deprecated","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Import { OnoHttpError } and use it as a base class: class MyError extends OnoHttpError {}","cause":"Attempting to use new OnoHttpError() directly, but it's a named export not a constructor","error":"TypeError: OnoHttpError is not a constructor"},{"fix":"httpError(404, 'Not Found') - use integer","cause":"Passing status code as string instead of number","error":"Error: Expected a numeric HTTP status code, got \"404\""},{"fix":"npm install ono ono-http","cause":"Missing ono peer dependency","error":"Cannot find module 'ono-http'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}