class MalformedRequestBodyError
extends Error
Since 0.5.0

Thrown when a request body cannot be parsed as JSON.

The cause is the platform SyntaxError the parse produced — kept for the log, never served: the caller-facing sentence is the fixed detail written here, composed only of framework-chosen words, so the masking exemption the brand earns cannot disclose body content (§3.7).

Examples

Example 1

try {
  const body = await ctx.request.json();
} catch (error) {
  if (error instanceof MalformedRequestBodyError) {
    // Answer 400; `error.cause` is the underlying SyntaxError.
  }
}

Constructors

MalformedRequestBodyError(cause: unknown)

Builds the error for one failed parse.

Parameters
cause: unknown

The platform SyntaxError the JSON parse produced

Properties

readonly
name: string

Discriminant for consumers that cannot use instanceof across realms.

Usage

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