Class: RestfulError::Wrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/restful_error/wrapper.rb

Instance Method Summary collapse

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

#messageObject



18
19
20
21
# File 'lib/restful_error/wrapper.rb', line 18

def message
  return message if message = @ex.try(:status_message)
  I18n.t @ex.class.name.underscore, default: [reason_phrase_key, @ex.class.name], scope: :restful_error
end

#reason_phraseObject



12
13
14
# File 'lib/restful_error/wrapper.rb', line 12

def reason_phrase
  RestfulError.reason_phrase(status_code)
end

#reason_phrase_keyObject



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_codeObject



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