function httpStatusHintOf
Since 0.4.0
httpStatusHintOf(error: unknown): HttpStatusHint | undefined

Reads the status hint an error was branded with.

Accepts unknown rather than Error because the one caller that matters — an error-handling catch — holds unknown, and a thrown non-Error value is legal JavaScript.

Examples

Example 1

try {
  await repo.findAll(query);
} catch (error) {
  const hint = httpStatusHintOf(error);
  if (hint !== undefined) {
    // Answer hint.status with hint.detail rather than a masked 500.
  }
}

Parameters

error: unknown

The thrown value to inspect

Return Type

HttpStatusHint | undefined

The hint, or undefined when the value carries none

Usage

import { httpStatusHintOf } from "common/src/index.ts";