{"id":18432,"library":"http-problem-details-mapper","title":"http-problem-details-mapper","description":"A library for mapping errors to RFC 7807 HTTP Problem Details (ProblemDocument) objects. Version 0.1.7 ships TypeScript types and follows Conventional Commits. It provides an extensible mapper pattern (ErrorMapper, MapperRegistry, MappingStrategy) to convert domain errors into structured HTTP error responses. Key differentiators: integrates with http-problem-details and express-http-problem-details for a complete REST error handling stack. Release cadence is low; version 0.1.x is stable and maintained. Peer dependency on http-problem-details (^0.1.0) required.","status":"active","version":"0.1.7","language":"javascript","source_language":"en","source_url":"https://github.com/PDMLab/http-problem-details-mapper","tags":["javascript","http","problem","error","http-problem","rfc7807","rest","api","typescript"],"install":[{"cmd":"npm install http-problem-details-mapper","lang":"bash","label":"npm"},{"cmd":"yarn add http-problem-details-mapper","lang":"bash","label":"yarn"},{"cmd":"pnpm add http-problem-details-mapper","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency required for ProblemDocument class","package":"http-problem-details","optional":false}],"imports":[{"note":"ESM supported; use named export. CommonJS require works but use destructuring.","wrong":"const ErrorMapper = require('http-problem-details-mapper').ErrorMapper","symbol":"ErrorMapper","correct":"import { ErrorMapper } from 'http-problem-details-mapper'"},{"note":"MapperRegistry is a named export, not default.","wrong":"import MapperRegistry from 'http-problem-details-mapper'","symbol":"MapperRegistry","correct":"import { MapperRegistry } from 'http-problem-details-mapper'"},{"note":"Class name is PascalCase; common camelCase mistake.","wrong":"const { defaultErrorMapper } = require('http-problem-details-mapper')","symbol":"DefaultErrorMapper","correct":"import { DefaultErrorMapper } from 'http-problem-details-mapper'"}],"quickstart":{"code":"import { ErrorMapper, MapperRegistry } from 'http-problem-details-mapper';\nimport { ProblemDocument } from 'http-problem-details';\n\nclass NotFoundError extends Error {\n  constructor(options) {\n    super();\n    this.message = `${options.type} with id ${options.id} not found`;\n  }\n}\n\nclass NotFoundErrorMapper extends ErrorMapper {\n  constructor() {\n    super(NotFoundError);\n  }\n  mapError(error) {\n    return new ProblemDocument({ status: 404, title: error.message, type: 'http://tempuri.org/NotFoundError' });\n  }\n}\n\nclass MyMappingStrategy {\n  constructor(registry) { this.registry = registry; }\n  map(error) {\n    const mapper = this.registry.getMapper(error);\n    if (mapper) return mapper.mapError(error);\n    throw new Error('Could not map error');\n  }\n}\n\nconst registry = new MapperRegistry().registerMapper(new NotFoundErrorMapper());\nconst strategy = new MyMappingStrategy(registry);\nconst error = new NotFoundError({ type: 'customer', id: '123' });\nconst problem = strategy.map(error);\nconsole.log(problem);","lang":"typescript","description":"Shows full setup: custom error, mapper, registration, and mapping with ProblemDocument."},"warnings":[{"fix":"Ensure the argument to super is the Error class itself, e.g., super(NotFoundError).","message":"ErrorMapper constructor takes an Error class (constructor function), not an instance. Passing an instance will break type checks and runtime mapping.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Extend ErrorMapper class rather than implementing IErrorMapper.","message":"IErrorMapper interface is deprecated. Use ErrorMapper base class instead.","severity":"deprecated","affected_versions":"<=0.1.7"},{"fix":"Either enable default mapper or always check mapper existence before calling mapError.","message":"MapperRegistry.getMapper throws if no mapper found when useDefaultErrorMapper is false. Default is true and returns DefaultErrorMapper.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Register a mapper for the error or set useDefaultErrorMapper to true in MapperRegistry constructor.","cause":"No mapper registered for the error type and useDefaultErrorMapper set to false.","error":"Error: Could not map error"},{"fix":"Use super(NotFoundError) not super(new NotFoundError()).","cause":"Passed an instance instead of a class to ErrorMapper constructor.","error":"TypeError: errorMapper is not a constructor"},{"fix":"npm install http-problem-details.","cause":"Missing peer dependency.","error":"Cannot find module 'http-problem-details'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}