Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
ajay-plivo committed May 30, 2024
1 parent 3100830 commit 15693a9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 32 deletions.
8 changes: 6 additions & 2 deletions lib/plivo/base/resource_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
64 changes: 34 additions & 30 deletions lib/plivo/base_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]}"
Expand All @@ -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
Expand Down

0 comments on commit 15693a9

Please sign in to comment.