Reference

std/http/error

std/http/src/error.trb

HttpError: what every operation of std/http fails with - the client's, the server's and the parser's - as one wrapper type, so a new kind of failure is never a breaking change (see "Algebraic Data Types and Pattern Matching" in CONCEPT.md).

type HttpError

type HttpError with Show, Error

What went wrong with a request or a response. The kind is a question (isTimeout(), statusCode(), ...), and a failure the parser found carries the status a server answers it with (HttpError.answerStatus).

fn timeout

static fn timeout(): HttpError

The server did not respond in time, or the client did not send its request in time.

fn connectionFailed

static fn connectionFailed(message: String): HttpError

The request never reached a server (DNS, refused connection, broken transport, ...).

fn network

static fn network(cause: NetworkError): HttpError

The network failed under the message: the failure of std/network, kept.

fn status

static fn status(code: Int, message: String): HttpError

The server responded, but not with success.

fn decodeFailed

static fn decodeFailed(cause: JsonError): HttpError

Response.json failed: the body was not the JSON Value expected.

fn tooLarge

static fn tooLarge(limit: Int): HttpError

A body that was read in one piece was longer than the limit that was given.

fn invalidText

static fn invalidText(cause: Utf8Error): HttpError

The bytes of the body are not UTF-8, so they are not a String.

fn malformed

static fn malformed(message: String): HttpError

A message that breaks the syntax of HTTP/1.1: a server answers it with 400 Bad Request.

fn headTooLarge

static fn headTooLarge(limit: Int): HttpError

A head longer than limit bytes, or with more fields than allowed: 431 Request Header Fields Too Large.

fn unsupported

static fn unsupported(message: String): HttpError

A feature of HTTP this implementation does not have, such as a transfer coding: 501 Not Implemented. The client answers it for a URI it does not reach, too: another scheme, an empty host, user information.

fn unsupportedVersion

static fn unsupportedVersion(version: String): HttpError

A version other than HTTP/1.0 and HTTP/1.1: 505 HTTP Version Not Supported.

fn incomplete

static fn incomplete(): HttpError

The connection ended in the middle of a message.

fn tooManyRedirects

static fn tooManyRedirects(limit: Int): HttpError

A Client was redirected more than limit times for one request, which its redirect policy allows.

fn isTimeout

fn isTimeout(): Bool

Whether the server did not respond in time.

fn isRetryable

fn isRetryable(): Bool

Worth trying again unchanged: timeouts, connection failures, 5xx responses.

fn statusCode

fn statusCode(): Int?

The status code, if the request reached the server at all.

fn answerStatus

fn answerStatus(): Int?

The status a server answers a request with that failed this way while it was read - by the server, or by a handler that read the body: 400 for a malformed message, a body cut short, text that is not UTF-8 or JSON that is not the type asked for; 408 for one that took too long; 413 for a body over its limit; 431 for a head over its limit; 501 for a coding that is not built; 505 for another version. None for everything else - the network broke, or the failure is the server's own.

fn show

fn show(): String

A message naming what went wrong, e.g. "404: Not Found" or "request timed out".

fn cause

fn cause(): Error?

The failure a rejected body carries, so a report can unwind the chain down to the field or the byte.

extend HttpError with From<Utf8Error>

extend HttpError with From<Utf8Error>

What makes body.lines() work: a stage over bytes, so it needs nothing of HTTP.

fn from

static fn from(value: Utf8Error): HttpError

extend HttpError with From<JsonError>

extend HttpError with From<JsonError>

...and what makes body.through(Json.items<User>()).checked() work without naming a second failure type.

fn from

static fn from(value: JsonError): HttpError

extend HttpError with From<NetworkError>

extend HttpError with From<NetworkError>

A failure of the connection under a message is the message's failure.

fn from

static fn from(value: NetworkError): HttpError