Module: Uploadcare::Internal::ErrorHandler

Included in:
Api::Rest, Api::Upload
Defined in:
lib/uploadcare/internal/error_handler.rb

Overview

Handles API errors and converts them to appropriate exceptions.

This module is included in API base classes to provide consistent error handling across all API requests. It parses error responses and raises typed exceptions.

Instance Method Summary collapse

Instance Method Details

#handle_error(error) ⇒ Object

Handle a failed API request and raise an appropriate exception.

Parses the error response and raises a typed exception based on the HTTP status code. Also handles Upload API errors which return status 200 with error details in the body.

Parameters:

  • error (Faraday::Error)

    The error from the HTTP client

Raises:



24
25
26
27
28
29
30
31
32
# File 'lib/uploadcare/internal/error_handler.rb', line 24

def handle_error(error)
  response = error.response
  return raise Uploadcare::Exception::RequestError, error.message if response.nil?

  catch_upload_errors(response)

  error_message = extract_error_message(response)
  raise_status_error(response, error_message)
end