Skip to content

struct Athena::Routing::Listeners::Error
inherits Struct #

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::HTTPExceptions 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

Class methods#

.subscribed_events : AED::SubscribedEvents #

View source

.new(error_renderer : ART::ErrorRendererInterface) #

View source

Methods#