struct Athena::Routing::Listeners::Error

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

Defined in:

listeners/error_listener.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(error_renderer : ART::ErrorRendererInterface) #

[View source]

Class Method Detail

def self.subscribed_events : AED::SubscribedEvents #

[View source]

Instance Method Detail

def call(event : ART::Events::Exception, dispatcher : AED::EventDispatcherInterface) : Nil #

[View source]