Class: Jsapi::Meta::RescueHandler

Inherits:
Base::Model show all
Defined in:
lib/jsapi/meta/rescue_handler.rb

Overview

Maps an error class to a response status.

Constant Summary

Constants included from Base::Attributes

Base::Attributes::DEFAULT_ARRAY, Base::Attributes::DEFAULT_HASH

Instance Method Summary collapse

Methods inherited from Base::Model

#inspect, #merge!, #reference?, #resolve

Methods included from Base::Attributes

#attribute, #attribute_names

Constructor Details

#initialize(keywords = {}) ⇒ RescueHandler

Returns a new instance of RescueHandler.



17
18
19
20
21
22
23
24
25
# File 'lib/jsapi/meta/rescue_handler.rb', line 17

def initialize(keywords = {})
  super
  unless error_class.is_a?(Class)
    raise ArgumentError, "#{error_class.inspect} isn't a class"
  end
  unless error_class <= StandardError
    raise ArgumentError, "#{error_class.inspect} isn't a rescuable class"
  end
end

Instance Method Details

#error_classObject

:attr: error_class The error class to be mapped.



10
# File 'lib/jsapi/meta/rescue_handler.rb', line 10

attribute :error_class, default: StandardError

#match?(exception) ⇒ Boolean

Returns true if exception is an instance of the class to be mapped, false otherwise.

Returns:

  • (Boolean)


28
29
30
# File 'lib/jsapi/meta/rescue_handler.rb', line 28

def match?(exception)
  exception.is_a?(error_class)
end

#statusObject

:attr: status The response status. The default is "default".



15
# File 'lib/jsapi/meta/rescue_handler.rb', line 15

attribute :status, default: 'default'