← index

HttpError

inherits Error · defined at web/01-error.qn:9

HttpError — throw a status (and optional body) from anywhere under a [Web]App; the dispatcher maps it onto the response:

(req.header:'authorization').defined?.else:{ HttpError.throw:401 }; HttpError.throw:422 body:#{ 'error':'bad email' };

Root-level by convention, not constraint: it reads as a sibling of the built-in error family (IoError, ValueError, TimeoutError, ParseError).

Class methods

throw:

Throw an HttpError carrying just a status; the [Web]App dispatcher maps it onto the response.

(req.header:'authorization').defined?.else:{ HttpError.throw:401 }

web/01-error.qn:29

throw: body:

Throw an HttpError with a status and a body for the dispatcher to render.

HttpError.throw:422 body:#{ 'error':'bad email' }

web/01-error.qn:34

Instance methods

body

The optional body for the error response (rendered through the app's respondTo: conventions), or nil.

web/01-error.qn:21

init:

Internal: default the status to 500 and derive the message ('HTTP 422').

web/01-error.qn:11

status

The HTTP status to answer with.

web/01-error.qn:18