isProblemDetailsResponse

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

function ยท experimental

function isProblemDetailsResponse(response: Response): boolean

Type guard that checks whether a Response has an application/problem+json content type.

The media type is compared without parameters (e.g. charset=utf-8 is ignored). Only application/problem+json is recognized; any other media type returns false.

response: Response

The Response to check.

Returns

true if the response has an application/problem+json content type, false otherwise.

Example: Usage

import {
  isProblemDetailsResponse,
  parseProblemDetailsResponse,
} from "@ende/http/unstable-problem-details";

const response = await fetch("https://api.example.com/resource");
if (isProblemDetailsResponse(response)) {
  const problem = await parseProblemDetailsResponse(response);
  console.error(problem.detail);
}

Source