Module: Uploadcare::Concerns::UploadErrorHandler

Includes:
Exception
Defined in:
lib/uploadcare/concern/upload_error_handler.rb

Overview

Wrapper for responses raises errors instead of returning monads

Instance Method Summary collapse

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/upload_error_handler.rb', line 14

def failure(response)
  catch_throttling_error(response)
  parsed_response = JSON.parse(response.body.to_s)
  raise RequestError, parsed_response['detail']
rescue JSON::ParserError
  raise RequestError, response.status
end