{"id":18333,"library":"express-http-problem-details","title":"Express HTTP Problem Details","description":"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.","status":"active","version":"0.2.1","language":"javascript","source_language":"en","source_url":"https://github.com/PDMLab/express-http-problem-details","tags":["javascript","express","error","http","problem","rfc7807","conneg","typescript"],"install":[{"cmd":"npm install express-http-problem-details","lang":"bash","label":"npm"},{"cmd":"yarn add express-http-problem-details","lang":"bash","label":"yarn"},{"cmd":"pnpm add express-http-problem-details","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency for middleware integration","package":"express","optional":false}],"imports":[{"note":"ESM import; commonjs require works but is discouraged.","wrong":"const { HttpProblemResponse } = require('express-http-problem-details')","symbol":"HttpProblemResponse","correct":"import { HttpProblemResponse } from 'express-http-problem-details'"},{"note":"Named export, not default. Available since v0.1.0.","wrong":"import ExpressMappingStrategy from 'express-http-problem-details'","symbol":"ExpressMappingStrategy","correct":"import { ExpressMappingStrategy } from 'express-http-problem-details'"},{"note":"No default export; must destructure in CJS.","wrong":"const HttpProblemResponse = require('express-http-problem-details')","symbol":"default","correct":"const HttpProblemResponse = require('express-http-problem-details').HttpProblemResponse"}],"quickstart":{"code":"import express from 'express';\nimport { HttpProblemResponse } from 'express-http-problem-details';\nimport { ProblemDocument } from 'http-problem-details';\nimport { DefaultMappingStrategy, MapperRegistry, ErrorMapper } from 'http-problem-details-mapper';\n\nclass NotFoundError extends Error {\n  constructor({ type, id }) {\n    super();\n    this.message = `${type} with id ${id} could not be found.`;\n  }\n}\n\nclass NotFoundErrorMapper extends ErrorMapper {\n  constructor() { super(NotFoundError); }\n  mapError(error) {\n    return new ProblemDocument({ status: 404, title: error.message, type: 'http://tempuri.org/NotFoundError' });\n  }\n}\n\nconst strategy = new DefaultMappingStrategy(\n  new MapperRegistry().registerMapper(new NotFoundErrorMapper())\n);\n\nconst server = express();\nserver.get('/', (req, res) => { throw new NotFoundError({ type: 'customer', id: '123' }); });\nserver.use((err, req, res, next) => { console.error(err.stack); next(err); });\nserver.use(HttpProblemResponse({ strategy }));\nserver.listen(3000);","lang":"typescript","description":"Express app using HttpProblemResponse middleware to map NotFoundError to RFC 7807 Problem Document."},"warnings":[{"fix":"Ensure HttpProblemResponse is the last error-handling middleware.","message":"Middleware must be placed after all other error-handling middleware that sends responses, otherwise Problem Document may not be generated.","severity":"gotcha","affected_versions":"*"},{"fix":"Use DefaultMappingStrategy from http-problem-details-mapper instead.","message":"ExpressMappingStrategy was deprecated in v0.2.0 in favor of DefaultMappingStrategy from http-problem-details-mapper.","severity":"deprecated","affected_versions":">=0.2.0"},{"fix":"Install express separately: npm install express.","message":"The package does not include express as a dependency; it must be installed separately.","severity":"gotcha","affected_versions":"*"},{"fix":"Always pass an object with a 'strategy' property that implements MappingStrategy.","message":"HttpProblemResponse expects a 'strategy' option; omitting it will cause a runtime error.","severity":"gotcha","affected_versions":"*"},{"fix":"Import { HttpProblemResponse } from 'express-http-problem-details' (capital H).","message":"In v0.1.0, the middleware was named 'httpProblemResponse' (lowercase); renamed to 'HttpProblemResponse' in v0.2.0.","severity":"breaking","affected_versions":">=0.2.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"server.use(HttpProblemResponse({ strategy }))","cause":"HttpProblemResponse called without arguments.","error":"TypeError: Cannot destructure property 'strategy' of 'undefined' or 'null'"},{"fix":"Use an instance of DefaultMappingStrategy from http-problem-details-mapper.","cause":"The 'strategy' object does not implement the MappingStrategy interface.","error":"TypeError: strategy.mapError is not a function"},{"fix":"Call registerMapper multiple times, or pass mappers individually.","cause":"MapperRegistry.registerMapper() expects a single mapper, not an array.","error":"TypeError: (intermediate value) is not iterable"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}