Class: Faraday::Response
- Inherits:
-
Object
- Object
- Faraday::Response
- Defined in:
- lib/better-faraday.rb
Instance Method Summary collapse
- #assert_2xx! ⇒ Object (also: #ok!, #assert_success!)
- #describe ⇒ Object
Instance Method Details
#assert_2xx! ⇒ Object Also known as: ok!, assert_success!
19 20 21 22 23 24 |
# File 'lib/better-faraday.rb', line 19 def assert_2xx! return self if status >= 200 && status <= 299 raise Faraday::HTTP422, describe if status == 422 raise Faraday::HTTP4xx, describe if status >= 400 && status <= 499 raise Faraday::Error, describe end |
#describe ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/better-faraday.rb', line 29 def describe [ "", "-- #{status} #{reason_phrase} --", "", "-- Request URL --", env.url.to_s, "", "-- Request method --", env.method.to_s.upcase, "", "-- Request headers --", ::JSON.generate(env.request_headers.tap { |x| x["Authorization"] = "SECRET" if x.key?("Authorization") }), "", "-- Request body --", env.request_body.to_s, "", "-- Response headers --", ::Hash === env.response_headers ? ::JSON.generate(env.response_headers) : "", "", "-- Response body --", env.body.to_s, "" ].join("\n") end |