Module: Uploadcare::Concerns::ErrorHandler
- Includes:
- Exception
- Defined in:
- lib/uploadcare/concern/error_handler.rb
Overview
Wrapper for responses raises errors instead of returning monads
Instance Method Summary collapse
-
#failure(response) ⇒ Object
Extension of ApiStruct's failure method.
-
#wrap(response) ⇒ Object
Extension of ApiStruct's wrap method.
Instance Method Details
#failure(response) ⇒ Object
Extension of ApiStruct's failure method
Raises errors instead of returning falsey objects
14 15 16 17 18 19 20 |
# File 'lib/uploadcare/concern/error_handler.rb', line 14 def failure(response) catch_upload_errors(response) parsed_response = JSON.parse(response.body.to_s) raise RequestError, parsed_response['detail'] || parsed_response.map { |k, v| "#{k}: #{v}" }.join('; ') rescue JSON::ParserError raise RequestError, response.body.to_s end |
#wrap(response) ⇒ Object
Extension of ApiStruct's wrap method
Catches throttling errors and Upload API errors
27 28 29 30 31 32 33 |
# File 'lib/uploadcare/concern/error_handler.rb', line 27 def wrap(response) raise_throttling_error(response) if response.status == 429 return failure(response) if response.status >= 300 catch_upload_errors(response) success(response) end |