Exception: WOTC::Error
- Inherits:
-
StandardError
- Object
- StandardError
- WOTC::Error
- Defined in:
- lib/wotc/error.rb
Overview
Custom error class for rescuing from all wotc.com errors
Direct Known Subclasses
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#http_method ⇒ Object
readonly
Returns the value of attribute http_method.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #error_sentence ⇒ Object
-
#initialize(response) ⇒ Error
constructor
A new instance of Error.
- #message ⇒ Object
- #raw_errors ⇒ Object
Constructor Details
#initialize(response) ⇒ Error
Returns a new instance of Error.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/wotc/error.rb', line 6 def initialize(response) @response = response.dup env = response.env # Use hash-style access for :method to avoid calling Kernel#method. # Plain Ruby only: this gem does not depend on ActiveSupport. http_method = env[:method].to_s.upcase @http_method = http_method.empty? ? "UNKNOWN" : http_method @url = env.url.to_s @status = response.status @body = response.body if @body.is_a?(Hash) && !@body.empty? && !@body.fetch("errors", nil).nil? @raw_errors = @body.fetch("errors") end super() end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
4 5 6 |
# File 'lib/wotc/error.rb', line 4 def errors @errors end |
#http_method ⇒ Object (readonly)
Returns the value of attribute http_method.
4 5 6 |
# File 'lib/wotc/error.rb', line 4 def http_method @http_method end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
4 5 6 |
# File 'lib/wotc/error.rb', line 4 def url @url end |
Instance Method Details
#error_sentence ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/wotc/error.rb', line 35 def error_sentence return if @raw_errors.nil? array = [] @raw_errors.each do |_, v| array += v end array.join(' ') end |
#message ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/wotc/error.rb', line 22 def <<-HEREDOC URL: #{@url} method: #{@http_method} response status: #{@status} response body: #{@body} HEREDOC end |
#raw_errors ⇒ Object
31 32 33 |
# File 'lib/wotc/error.rb', line 31 def raw_errors @raw_errors end |