Skip to content

Status

A response whose status is outside 200..=299.

Raised by a request that completes normally but reports a failure status, unless status: :IGNORE: was passed. The response metadata and the first 64 KiB of the body are kept on the error, so a failed request can be diagnosed without a second round trip.

Example

try
  get "https://example.com/missing"
catch Status: err
  echo $err.status
  echo $err.text()

Inherits from: Error

Fields

headers @ Map[Str, Str | time.DateTime] [get]

The response headers, as Response.headers presents them.

status @ Int [get]

The HTTP status code.

truncated @ Bool [get]

Whether the saved body excerpt was cut off, either by the 64 KiB limit or by a read error while buffering it.

url @ (url.Url | nil) [get]

The response URL, or nil when none was attached.

Methods

body() -> Bin

The saved body excerpt.

json() -> json.DecodeValue

The saved body excerpt, parsed as JSON.

Errors

DataError if the excerpt is not valid UTF-8 or not valid JSON. A truncated excerpt is usually not valid JSON.

text() -> Str

The saved body excerpt as text.

Errors

Exception Condition
DataError The excerpt is not valid UTF-8