struct Athena::Routing::Listeners::Error
- Athena::Routing::Listeners::Error
- Struct
- Value
- Object
Overview
Handles an exception by converting it into an ART::Response
via an ART::ErrorRendererInterface
.
This listener defines a log_exception
protected method that determines how the exception gets logged.
Non ART::Exceptions::HTTPException
s and server errors are logged as errors.
Validation errors (ART::Exceptions::UnprocessableEntity
) are logged as notice.
Everything else is logged as a warning.
The method can be redefined if different logic is desired.
struct ART::Listeners::Error
# :inherit:
protected def log_exception(exception : Exception, & : -> String) : Nil
# Don't log anything if an exception is some specific type.
return if exception.is_a? MyException
# Exception types could also include modules to act as interfaces to determine their level, E.g. `include NoticeException`.
if exception.is_a? NoticeException
Log.notice(exception: exception) { yield }
return
end
# Otherwise fallback to the default implementation.
previous_def
end
end
Included Modules
- Athena::EventDispatcher::EventListenerInterface
Defined in:
listeners/error_listener.crConstructors
Class Method Summary
Instance Method Summary
Constructor Detail
Class Method Detail
Instance Method Detail
def call(event : ART::Events::Exception, dispatcher : AED::EventDispatcherInterface) : Nil
#