Class: Eloquant::FaradayMiddleware::Response
- Inherits:
-
FaradayMiddleware::ParseJson
- Object
- FaradayMiddleware::ParseJson
- Eloquant::FaradayMiddleware::Response
- Defined in:
- lib/eloquant/faraday_middleware/response.rb
Instance Method Summary collapse
Instance Method Details
#handle_errors!(errors) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/eloquant/faraday_middleware/response.rb', line 21 def handle_errors!(errors) error = errors.first fail Eloquant::Errors::Unknown if error.nil? fail Eloquant::Errors.find_by_response_code(error[:code].to_i), error[:message] end |
#process_response(env) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/eloquant/faraday_middleware/response.rb', line 10 def process_response(env) super data = env[:body] fail Eloquant::Errors::EmptyResponse if data.nil? fail Eloquant::Errors::Error, data[:error_description] if data.key?(:error) handle_errors!(data[:errors]) unless data.fetch(:success, true) end |