Class: ActionNetworkRest::Response::RaiseError
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- ActionNetworkRest::Response::RaiseError
- Defined in:
- lib/action_network_rest/response/raise_error.rb
Instance Method Summary collapse
-
#error_message(response) ⇒ Object
rubocop:enable Style/GuardClause.
-
#on_complete(response) ⇒ Object
rubocop:disable Style/GuardClause.
Instance Method Details
#error_message(response) ⇒ Object
rubocop:enable Style/GuardClause
29 30 31 |
# File 'lib/action_network_rest/response/raise_error.rb', line 29 def (response) "#{response[:method].to_s.upcase} #{response[:url]}: #{response[:status]} \n\n #{response[:body]}" end |
#on_complete(response) ⇒ Object
rubocop:disable Style/GuardClause
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/action_network_rest/response/raise_error.rb', line 7 def on_complete(response) status_code = response[:status].to_i if (400...600).cover? status_code if status_code == 400 && response[:body].include?('error') error_hsh = JSON.parse(response[:body]) = error_hsh['error'] if == 'You must specify a valid person id' raise MustSpecifyValidPersonId, (response) end elsif status_code == 404 raise NotFoundError, (response) elsif status_code == 429 raise TooManyRequests, (response) else raise ResponseError, (response) end end end |