function rfc9457Formatter
Since 0.1.0
rfc9457Formatter(
error: Error,
ctx?: IRequestContext
): ProblemDetails

Format an error as RFC 9457 Problem Details.

type is about:blank for problems whose only semantics are their status code, and the framework validation problem type when the error carries an errors extension. Every other member is assembled identically to the deprecated RFC 7807 formatter.

Examples

Example 1

rfc9457Formatter(notFound('User 42 does not exist'), ctx);
// {
//   type: 'about:blank',
//   title: 'Not Found',
//   status: 404,
//   detail: 'User 42 does not exist',
//   instance: '/users/42',
// }

Parameters

error: Error

The thrown error to format

optional
ctx: IRequestContext

Optional request context (used for instance)

Return Type

An RFC 9457 Problem Details body

Usage

import { rfc9457Formatter } from "exceptions/src/index.ts";