Module: Hanami::Action::Rack::Errors Private

Defined in:
lib/hanami/action/rack/errors.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

This module provides method to set exceptions to Rack env:

* `rack.errors` - IO for errors, as requested by Rack SPEC
* `rack.exception` - De-facto standard for Ruby exception tracking SaaS

Constant Summary collapse

RACK_ERRORS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 1.3.3

"rack.errors"
RACK_EXCEPTION =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 1.3.3

"rack.exception"

Class Method Summary collapse

Class Method Details

._dump_exception(exception) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Format exception info with name and backtrace

Parameters:

  • exception (Exception)

Since:

  • 1.3.3


47
48
49
# File 'lib/hanami/action/rack/errors.rb', line 47

def self._dump_exception(exception)
  [[exception.class, exception.message].compact.join(": "), *exception.backtrace].join("\n\t")
end

.set(env, exception) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Set exception in Rack env

Parameters:

  • env (Hash)

    the Rack environment

  • exception (Exception)

    the exception to set

Since:

  • 1.3.3


32
33
34
35
36
37
38
39
# File 'lib/hanami/action/rack/errors.rb', line 32

def self.set(env, exception)
  env[RACK_EXCEPTION] = exception

  return unless errors = env[RACK_ERRORS] # rubocop:disable Lint/AssignmentInCondition

  errors.write(_dump_exception(exception))
  errors.flush
end