Skip to content

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

Handles an exception by converting it into an ATH::Response via an ATH::ErrorRendererInterface.

This listener defines a log_exception protected method that determines how the exception gets logged. Non ATH::Exceptions::HTTPExceptions and server errors are logged as errors. Validation errors (ATH::Exceptions::UnprocessableEntity) are logged as notice. Everything else is logged as a warning. The method can be redefined if different logic is desired.

struct ATH::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

Constructors#

.new(error_renderer : ATH::ErrorRendererInterface)#

View source

Methods#

#on_exception(event : ATH::Events::Exception) : Nil#

View source