From 15693a933ac4bfb96d44bb294dcb2bda634ae819 Mon Sep 17 00:00:00 2001 From: ajay-plivo Date: Thu, 30 May 2024 13:54:20 +0530 Subject: [PATCH] test --- lib/plivo/base/resource_interface.rb | 8 +++- lib/plivo/base_client.rb | 64 +++++++++++++++------------- 2 files changed, 40 insertions(+), 32 deletions(-) diff --git a/lib/plivo/base/resource_interface.rb b/lib/plivo/base/resource_interface.rb index 2f338b06..074e3040 100644 --- a/lib/plivo/base/resource_interface.rb +++ b/lib/plivo/base/resource_interface.rb @@ -108,11 +108,15 @@ def perform_list(params = nil) def perform_list_with_response(params = nil) response_json = @_client.send_request(@_resource_uri, 'GET', params, nil, false, is_voice_request: @_is_voice_request) - # parse_and_set(response_json) + objects = if response_json["response"]["objects"].empty? + [] + else + parse_and_set_list(response_json["response"]["objects"]) + end { api_id: response_json["api_id"], meta: response_json["response"]["meta"], - objects: parse_and_set_list(response_json["response"]["objects"]) + objects: objects } end diff --git a/lib/plivo/base_client.rb b/lib/plivo/base_client.rb index 764dbbc5..50673731 100644 --- a/lib/plivo/base_client.rb +++ b/lib/plivo/base_client.rb @@ -343,41 +343,41 @@ def send_delete(resource_path, data, timeout, options = nil) def handle_response_exceptions(response) exception_mapping = { - 400 => [ - Exceptions::ValidationError, - 'A parameter is missing or is invalid while accessing resource' - ], - 401 => [ - Exceptions::AuthenticationError, - 'Failed to authenticate while accessing resource' - ], - 404 => [ - Exceptions::ResourceNotFoundError, - 'Resource not found' - ], - 405 => [ - Exceptions::InvalidRequestError, - 'HTTP method used is not allowed to access resource' - ], - 409 => [ - Exceptions::InvalidRequestError, - 'Conflict' - ], - 422 => [ - Exceptions::InvalidRequestError, - 'Unprocessable Entity' - ], - 500 => [ - Exceptions::PlivoServerError, - 'A server error occurred while accessing resource' - ] + 400 => [ + Exceptions::ValidationError, + 'A parameter is missing or is invalid while accessing resource' + ], + 401 => [ + Exceptions::AuthenticationError, + 'Failed to authenticate while accessing resource' + ], + 404 => [ + Exceptions::ResourceNotFoundError, + 'Resource not found' + ], + 405 => [ + Exceptions::InvalidRequestError, + 'HTTP method used is not allowed to access resource' + ], + 409 => [ + Exceptions::InvalidRequestError, + 'Conflict' + ], + 422 => [ + Exceptions::InvalidRequestError, + 'Unprocessable Entity' + ], + 500 => [ + Exceptions::PlivoServerError, + 'A server error occurred while accessing resource' + ] } response_json = response[:body] - return unless exception_mapping.key? response[:status] + return unless exception_mapping.key?(response[:status]) exception_now = exception_mapping[response[:status]] - error_message = if (response_json.is_a? Hash) && (response_json.key? 'error') + error_message = if response_json.is_a?(Hash) && response_json.key?('error') response_json['error'] else exception_now[1] + " at: #{response[:url]}" @@ -386,6 +386,10 @@ def handle_response_exceptions(response) error_message = error_message['error'] end + # Add api_id to the error message if present + if response_json.is_a?(Hash) && response_json.key?('api_id') + error_message += " (api_id: #{response_json['api_id']})" + end raise exception_now[0], error_message.to_s end end