From 2858a0874c3a1c11871355242923ca7a2e124627 Mon Sep 17 00:00:00 2001 From: kraju3 Date: Fri, 10 Jan 2025 14:35:03 -0600 Subject: [PATCH] Handle response objects of instance String for API errors --- lib/nylas/handler/http_client.rb | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/nylas/handler/http_client.rb b/lib/nylas/handler/http_client.rb index 1ba3d8b7..97478601 100644 --- a/lib/nylas/handler/http_client.rb +++ b/lib/nylas/handler/http_client.rb @@ -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.