Registry / http-networking / express-http-problem-details

express-http-problem-details

JSON →
library0.2.1jsnpmunverified

Express middleware for RFC 7807 HTTP Problem Details content negotiation. Current stable version 0.2.1. It integrates with http-problem-details-mapper to map custom Node.js errors to standard Problem Documents. Key differentiators: automatic content negotiation based on Accept header, ships TypeScript types, and builds on the PDMLab ecosystem of problem-details libraries. Release cadence is low, with the last release in 2020.

npm install express-http-problem-details
INSTALL
IMPORT
SIG · EXPRESS-HTTP-PROBL
E
express-http-problem-details
http-networkingjavascriptv0.2.1
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

HttpProblemResponse
✓ import { HttpProblemResponse } from 'express-http-problem-details'
✗ const { HttpProblemResponse } = require('express-http-problem-details')
ESM import; commonjs require works but is discouraged.
ExpressMappingStrategy
✓ import { ExpressMappingStrategy } from 'express-http-problem-details'
✗ import ExpressMappingStrategy from 'express-http-problem-details'
Named export, not default. Available since v0.1.0.
default
✓ const HttpProblemResponse = require('express-http-problem-details').HttpProblemResponse
✗ const HttpProblemResponse = require('express-http-problem-details')
No default export; must destructure in CJS.

Express app using HttpProblemResponse middleware to map NotFoundError to RFC 7807 Problem Document.

import express from 'express'; import { HttpProblemResponse } from 'express-http-problem-details'; import { ProblemDocument } from 'http-problem-details'; import { DefaultMappingStrategy, MapperRegistry, ErrorMapper } from 'http-problem-details-mapper'; class NotFoundError extends Error { constructor({ type, id }) { super(); this.message = `${type} with id ${id} could not be found.`; } } class NotFoundErrorMapper extends ErrorMapper { constructor() { super(NotFoundError); } mapError(error) { return new ProblemDocument({ status: 404, title: error.message, type: 'http://tempuri.org/NotFoundError' }); } } const strategy = new DefaultMappingStrategy( new MapperRegistry().registerMapper(new NotFoundErrorMapper()) ); const server = express(); server.get('/', (req, res) => { throw new NotFoundError({ type: 'customer', id: '123' }); }); server.use((err, req, res, next) => { console.error(err.stack); next(err); }); server.use(HttpProblemResponse({ strategy })); server.listen(3000);
Debug
Known issues
gotchaMiddleware must be placed after all other error-handling middleware that sends responses, otherwise Problem Document may not be generated.
fix
Ensure HttpProblemResponse is the last error-handling middleware.
affects: *
deprecatedExpressMappingStrategy was deprecated in v0.2.0 in favor of DefaultMappingStrategy from http-problem-details-mapper.
fix
Use DefaultMappingStrategy from http-problem-details-mapper instead.
affects: >=0.2.0
gotchaThe package does not include express as a dependency; it must be installed separately.
fix
Install express separately: npm install express.
affects: *
gotchaHttpProblemResponse expects a 'strategy' option; omitting it will cause a runtime error.
fix
Always pass an object with a 'strategy' property that implements MappingStrategy.
affects: *
breakingIn v0.1.0, the middleware was named 'httpProblemResponse' (lowercase); renamed to 'HttpProblemResponse' in v0.2.0.
fix
Import { HttpProblemResponse } from 'express-http-problem-details' (capital H).
affects: >=0.2.0
Errors
Common errors & fixes
TypeError: Cannot destructure property 'strategy' of 'undefined' or 'null'
HttpProblemResponse called without arguments.
fix
server.use(HttpProblemResponse({ strategy }))
TypeError: strategy.mapError is not a function
The 'strategy' object does not implement the MappingStrategy interface.
fix
Use an instance of DefaultMappingStrategy from http-problem-details-mapper.
TypeError: (intermediate value) is not iterable
MapperRegistry.registerMapper() expects a single mapper, not an array.
fix
Call registerMapper multiple times, or pass mappers individually.
Upgrade
Version history
0.2.1latest on npm
Audit
Dependencies
expressrequiredpeer dependency for middleware integration
Agent activity
5 hits · last 30 days
node
4
OpenAI (training)
1
Resources
express-http-problem-details — npm install express-http-problem-details · libregistry