Class: RestfulError::Wrapper
- Inherits:
-
Object
- Object
- RestfulError::Wrapper
- Defined in:
- lib/restful_error/wrapper.rb
Instance Method Summary collapse
-
#initialize(ex) ⇒ Wrapper
constructor
A new instance of Wrapper.
- #message ⇒ Object
- #reason_phrase ⇒ Object
- #reason_phrase_key ⇒ Object
- #set_env(env) ⇒ Object
- #status_code ⇒ Object
Constructor Details
#initialize(ex) ⇒ Wrapper
3 4 5 |
# File 'lib/restful_error/wrapper.rb', line 3 def initialize(ex) @ex = ex end |
Instance Method Details
#message ⇒ Object
18 19 20 21 |
# File 'lib/restful_error/wrapper.rb', line 18 def return if = @ex.try(:status_message) I18n.t @ex.class.name.underscore, default: [reason_phrase_key, @ex.class.name], scope: :restful_error end |
#reason_phrase ⇒ Object
12 13 14 |
# File 'lib/restful_error/wrapper.rb', line 12 def reason_phrase RestfulError.reason_phrase(status_code) end |
#reason_phrase_key ⇒ Object
15 16 17 |
# File 'lib/restful_error/wrapper.rb', line 15 def reason_phrase_key reason_phrase.downcase.gsub(/\s|-/, '_').to_sym end |
#set_env(env) ⇒ Object
6 7 8 |
# File 'lib/restful_error/wrapper.rb', line 6 def set_env(env) @env = env end |
#status_code ⇒ Object
9 10 11 |
# File 'lib/restful_error/wrapper.rb', line 9 def status_code Rack::Utils.status_code(@ex.try(:status_code)).nonzero? || ActionDispatch::ExceptionWrapper.new(@env, @ex).status_code end |