module Athena::Routing::Exceptions

Overview

Exception handling in Athena is similar to exception handling in any Crystal program, with the addition of a new unique exception type, ART::Exceptions::HTTPException.

When an exception is raised, Athena emits the ART::Events::Exception event to allow an opportunity for it to be handled. If the exception goes unhandled, i.e. no listener set an ART::Response on the event, then the request is finished and the exception is reraised. Otherwise, that response is returned, setting the status and merging the headers on the exceptions if it is an ART::Exceptions::HTTPException. See ART::Listeners::Error and ART::ErrorRendererInterface for more information on how exceptions are handled by default.

To provide the best response to the client, non ART::Exceptions::HTTPException should be rescued and converted into a corresponding ART::Exceptions::HTTPException. Custom HTTP errors can also be defined by inheriting from ART::Exceptions::HTTPException or a child type. A use case for this could be allowing for additional data/context to be included within the exception that ultimately could be used in a ART::Events::Exception listener.

Defined in:

athena.cr
exceptions/http_exception.cr