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.

http-networkingweb-framework
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 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

ESM import; commonjs require works but is discouraged.

import { HttpProblemResponse } from 'express-http-problem-details'

Named export, not default. Available since v0.1.0.

import { ExpressMappingStrategy } from 'express-http-problem-details'

No default export; must destructure in CJS.

const HttpProblemResponse = require('express-http-problem-details').HttpProblemResponse

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 footguns
gotchaMiddleware must be placed after all other error-handling middleware that sends responses, otherwise Problem Document may not be generated.
deprecatedExpressMappingStrategy was deprecated in v0.2.0 in favor of DefaultMappingStrategy from http-problem-details-mapper.
gotchaThe package does not include express as a dependency; it must be installed separately.
gotchaHttpProblemResponse expects a 'strategy' option; omitting it will cause a runtime error.
breakingIn v0.1.0, the middleware was named 'httpProblemResponse' (lowercase); renamed to 'HttpProblemResponse' in v0.2.0.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
9 hits · last 30 days
gptbot
4
ahrefsbot
4
script
1
Resources