Registry / http-networking / http-problem-details-mapper

http-problem-details-mapper

JSON →
library0.1.7jsnpmunverified

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.

npm install http-problem-details-mapper
INSTALL
IMPORT
SIG · HTTP-PROBLEM-DETAI
H
http-problem-details-mapper
http-networkingjavascriptv0.1.7
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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.

ErrorMapper
import { ErrorMapper } from 'http-problem-details-mapper'
const ErrorMapper = require('http-problem-details-mapper').ErrorMapper
ESM supported; use named export. CommonJS require works but use destructuring.
MapperRegistry
import { MapperRegistry } from 'http-problem-details-mapper'
import MapperRegistry from 'http-problem-details-mapper'
MapperRegistry is a named export, not default.
DefaultErrorMapper
import { DefaultErrorMapper } from 'http-problem-details-mapper'
const { defaultErrorMapper } = require('http-problem-details-mapper')
Class name is PascalCase; common camelCase mistake.

Shows full setup: custom error, mapper, registration, and mapping with ProblemDocument.

import { ErrorMapper, MapperRegistry } from 'http-problem-details-mapper'; import { ProblemDocument } from 'http-problem-details'; class NotFoundError extends Error { constructor(options) { super(); this.message = `${options.type} with id ${options.id} not found`; } } class NotFoundErrorMapper extends ErrorMapper { constructor() { super(NotFoundError); } mapError(error) { return new ProblemDocument({ status: 404, title: error.message, type: 'http://tempuri.org/NotFoundError' }); } } class MyMappingStrategy { constructor(registry) { this.registry = registry; } map(error) { const mapper = this.registry.getMapper(error); if (mapper) return mapper.mapError(error); throw new Error('Could not map error'); } } const registry = new MapperRegistry().registerMapper(new NotFoundErrorMapper()); const strategy = new MyMappingStrategy(registry); const error = new NotFoundError({ type: 'customer', id: '123' }); const problem = strategy.map(error); console.log(problem);
Debug
Known issues
gotchaErrorMapper constructor takes an Error class (constructor function), not an instance. Passing an instance will break type checks and runtime mapping.
fix
Ensure the argument to super is the Error class itself, e.g., super(NotFoundError).
affects: >=0.1.0
deprecatedIErrorMapper interface is deprecated. Use ErrorMapper base class instead.
fix
Extend ErrorMapper class rather than implementing IErrorMapper.
affects: <=0.1.7
gotchaMapperRegistry.getMapper throws if no mapper found when useDefaultErrorMapper is false. Default is true and returns DefaultErrorMapper.
fix
Either enable default mapper or always check mapper existence before calling mapError.
affects: >=0.1.0
Errors
Common errors & fixes
Error: Could not map error
No mapper registered for the error type and useDefaultErrorMapper set to false.
fix
Register a mapper for the error or set useDefaultErrorMapper to true in MapperRegistry constructor.
TypeError: errorMapper is not a constructor
Passed an instance instead of a class to ErrorMapper constructor.
fix
Use super(NotFoundError) not super(new NotFoundError()).
Cannot find module 'http-problem-details'
Missing peer dependency.
fix
npm install http-problem-details.
Upgrade
Version history
0.1.7latest on npm
Audit
Dependencies
http-problem-detailsrequiredPeer dependency required for ProblemDocument class
Agent activity
8 hits · last 30 days
node
8
Resources
http-problem-details-mapper — npm install http-problem-details-mapper · libregistry