parseProblemDetailsResponse

import { parseProblemDetailsResponse } from "jsr:@ende/http/unstable-problem-details";

function · experimental

async function parseProblemDetailsResponse<T extends ProblemDetailsExtensions = Record<string, never>>(input: Response): Promise<ProblemDetails<T>>

Parses a Response body into a ProblemDetails.

Reads the response body as JSON and delegates to parseProblemDetails. Standard members with invalid types are silently dropped per RFC 9457 §3.1. Does not throw on missing fields — the RFC makes all members optional. Extension member types provided via T are asserted at the type level only; values are not validated at runtime.

Note: this consumes the response body. The Response cannot be re-read after this call.

input: Response

The Response whose JSON body will be parsed.

Returns

A promise that resolves to the parsed problem details.

Example: Parse from a Response

import { parseProblemDetailsResponse } from "@ende/http/unstable-problem-details";
import { assertEquals } from "@ende/assert";

const response = new Response(
  JSON.stringify({ type: "about:blank", status: 404, title: "Not Found" }),
  { headers: { "Content-Type": "application/problem+json" } },
);
const problem = await parseProblemDetailsResponse(response);
assertEquals(problem.status, 404);
assertEquals(problem.title, "Not Found");

Source