struct Athena::HTTPKernel::Listeners::Error
inherits Struct
#
Handles an exception by converting it into an AHTTP::Response via an AHK::ErrorRendererInterface.
This listener defines a log_exception protected method that determines how the exception gets logged.
Non AHK::Exception::HTTPExceptions and server errors are logged as errors.
Validation errors (AHK::Exception::UnprocessableEntity) are logged as notice.
Everything else is logged as a warning.
The method can be redefined if different logic is desired.
struct AHK::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