Skip to content

Commit

Permalink
Handle response objects of instance String for API errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kraju3 committed Jan 10, 2025
1 parent a8ca3f7 commit 2858a08
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions lib/nylas/handler/http_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,24 @@ def error_hash_to_exception(response, status_code, path)

def throw_error(response, status_code)
error_obj = response[:error]
provider_error = error_obj.fetch(:provider_error, nil)

NylasApiError.new(error_obj[:type], error_obj[:message], status_code, provider_error,
response[:request_id])
# If `error_obj` is just a string, turn it into a hash with default keys.
if error_obj.is_a?(String)
error_obj = {
type: "NylasApiError",
message: error_obj
}
end

provider_error = error_obj.fetch(:provider_error, nil) if error_obj.is_a?(Hash)

NylasApiError.new(
error_obj[:type],
error_obj[:message],
status_code,
provider_error,
response[:request_id]
)
end

# Adds query parameters to a URL.
Expand Down

0 comments on commit 2858a08

Please sign in to comment.