Exception: EhbrsRubyUtils::WebUtils::RequestError
- Inherits:
-
RuntimeError
- Object
- RuntimeError
- EhbrsRubyUtils::WebUtils::RequestError
- Defined in:
- lib/ehbrs_ruby_utils/web_utils/request_error.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.by_error(response) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ehbrs_ruby_utils/web_utils/request_error.rb', line 13 def by_error(response) return new(response, "status #{response.status}") unless response.status.to_s.match?(/\A2\d{2}\z/) data = ::JSON.parse(response.body_str) return nil unless data.is_a?(::Hash) errors = data['errors'] || {} return nil if errors.empty? new(response, "errors #{errors.pretty_inspect}") end |
.raise_if_error(response) ⇒ Object
9 10 11 |
# File 'lib/ehbrs_ruby_utils/web_utils/request_error.rb', line 9 def raise_if_error(response) by_error(response).if_present { |v| raise v } end |
Instance Method Details
#build_message ⇒ String
31 32 33 |
# File 'lib/ehbrs_ruby_utils/web_utils/request_error.rb', line 31 def "Request for \"#{response.url}\" failed: #{}\nBody file: #{body_file_path}" end |