Module: Armrest::Api::HandleResponse
- Included in:
- Mods
- Defined in:
- lib/armrest/api/handle_response.rb
Instance Method Summary collapse
- #load_json(resp) ⇒ Object
-
#ok?(http_code) ⇒ Boolean
Note: 422 is Unprocessable Entity.
Instance Method Details
#load_json(resp) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/armrest/api/handle_response.rb', line 5 def load_json(resp) if ok?(resp.code) data = JSON.load(resp.body).deep_transform_keys(&:underscore) Response.new(data) else logger.info "Error: Non-successful http response status code: #{resp.code}" logger.info "headers: #{resp.each_header.to_h.inspect}" raise "Azure API called failed" end end |
#ok?(http_code) ⇒ Boolean
Note: 422 is Unprocessable Entity. This means an invalid data payload was sent. We want that to error and raise
18 19 20 21 |
# File 'lib/armrest/api/handle_response.rb', line 18 def ok?(http_code) http_code =~ /^20/ || http_code =~ /^40/ end |