problem-details-http
raw JSON → 2.0.0 verified Sat Apr 25 auth: no javascript
Library for HTTP problem details (RFC 7807) error responses. Current stable version is 2.0.0, updated frequently via GitHub. Supports building and sending consistent error payloads with optional extension members. Differentiator: fluent builder pattern, defaults for status codes and titles, TypeScript types included, zero dependencies.
Common errors
error Cannot find module 'problem-details-http' or its corresponding type declarations. ↓
cause Package installed as devDependency or not installed; or missing types.
fix
Run
npm install problem-details-http (not --save-dev). Add "types": "dist/index.d.ts" to tsconfig.json if needed. error TypeError: PDBuilder.fromDetail is not a function ↓
cause Using CommonJS require with ESM-only package.
fix
Use
import { PDBuilder } from 'problem-details-http' or enable ES modules in project. error Property 'setStatus' does not exist on type 'PDBuilder'. ↓
cause Upgraded from v1.x to v2.x where `setStatus` was removed.
fix
Replace
.setStatus() with .status(). Warnings
breaking v2.0: Default import removed; must use named import { PDBuilder }. ↓
fix Change `import problemDetailsHttp from 'problem-details-http'` to `import { PDBuilder } from 'problem-details-http'`.
gotcha PDBuilder.fromDetail() is the only entry point; PDBuilder constructor is private. ↓
fix Always start with `PDBuilder.fromDetail('...')`.
deprecated The `setStatus` method was renamed to `status` in v1.5, but old name still works. ↓
fix Use `.status()` instead of `.setStatus()`.
Install
npm install problem-details-http yarn add problem-details-http pnpm add problem-details-http Imports
- PDBuilder wrong
const PDBuilder = require('problem-details-http')correctimport { PDBuilder } from 'problem-details-http' - default
import problemDetailsHttp from 'problem-details-http' - ProblemDetail
import type { ProblemDetail } from 'problem-details-http'
Quickstart
import { PDBuilder } from 'problem-details-http';
const pd = PDBuilder.fromDetail('Resource not found')
.type('https://example.com/errors/not-found')
.title('Not Found')
.status(404)
.instance('/api/users/123')
.build();
console.log(pd);
// {
// type: 'https://example.com/errors/not-found',
// status: 404,
// title: 'Not Found',
// detail: 'Resource not found',
// instance: '/api/users/123'
// }