The `error-http-response` package provides a utility to convert JavaScript `Error` objects into standardized HTTP problem detail objects, adhering to RFC 7807. It's currently stable at version 3.0.1, with major releases primarily driven by updates to the minimal supported Node.js version. The library automatically maps standard error properties like `name`, `message`, and `stack` to the generated HTTP response fields, and allows for extensive customization via `error.http` properties or direct options. It supports both Node.js (>=18.18.0) and browser environments, and ships with TypeScript definitions, making it suitable for modern JavaScript and TypeScript projects that need to consistently format API error responses without manual serialization.
npm install error-http-responseVerified import paths — ran on the pinned version, not inferred.
Demonstrates converting a custom error with additional properties into an RFC 7807-compliant HTTP problem details object, overriding some fields.
Ensure your Node.js environment is version `18.18.0` or higher before upgrading to version 3.x of this package.
Ensure your Node.js environment is version `16.17.0` or higher before upgrading to version 2.x of this package.
Always use `import errorHttpResponse from 'error-http-response';` to load this package. For older Node.js versions or CommonJS projects, consider using a tool like `esm` or a bundler.
In your `tsconfig.json`, ensure `"module"` is set to an ES module target like `"NodeNext"` or `"ESNext"`.
Change `const errorHttpResponse = require('error-http-response');` to `import errorHttpResponse from 'error-http-response';`.Update your `tsconfig.json` to configure TypeScript to output ES modules, for example, by setting `"module": "NodeNext"` or `"module": "ESNext"`.
No dependency data recorded yet.