Class: Wrangler::ExceptionHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/wrangler/exception_handler.rb

Overview

class that holds configuration for the exception handling logic. may also include a helper method or two, but the main interaction with ExceptionHandler is setting and getting config, e.g.

Wrangler::ExceptionHandler.configure do |handler_config| handler_config.merge! :key => value end

Class Method Summary collapse

Class Method Details

.config ⇒ Object

give access to config



134
135
136
# File 'lib/wrangler/exception_handler.rb', line 134

def self.config
  @@config
end

.configure {|@@config| ... } ⇒ Object

Allows for overriding default configuration settings. in your environment.rb or environments/.rb, use a block that accepts one argument

  • recommend against naming it 'config' as you will probably be calling it within the config block in env.rb...):

  • note that some of the config values are arrays or hashes; you can overwrite them completely, delete or insert/merge new entries into the default values as you see fit...but in most cases, recommend AGAINST overwriting the arrays/hashes completely unless you don't want to take advantage of lots of out-of-the-box config

    Wrangler::ExceptionHandler.configure do |handler_config| handler_config = value1 handler_config = value2 handler_config.merge! :subkey => value handler_config << another_value end

OR

Wrangler::ExceptionHandler.configure do |handler_config|
handler_config.merge! :key1 => value1,
                      :key2 => value2,
handler_config[:key_for_a_hash].merge! :subkey => value
handler_config[:key_for_an_array] << another_value
end

NOTE: sure, you can change this configuration on the fly in your app, but we don't recommend it. plus, if you do and you're using delayed_job, there may end up being configuration differences between the rails process and the delayed_job process, resulting in unexpected behavior. so recommend you just modify this in the environment config files...or if you're doing something sneaky, you're on your own.

Yields:



173
174
175
# File 'lib/wrangler/exception_handler.rb', line 173

def self.configure(&block)
  yield @@config
end

.status_code_for_exception(exception) ⇒ Object

translate the exception class to an http status code, using default code (set in config) if the exception class isn't excplicitly mapped to a status code in config



182
183
184
185
186
187
188
189
# File 'lib/wrangler/exception_handler.rb', line 182

def self.status_code_for_exception(exception)
  if exception.respond_to?(:status_code)
    return exception.status_code
  else
    return config[:error_class_status_codes][exception.class.name] ||
           config[:error_class_status_codes][:default]
  end
end