Skip to content

Commit

Permalink
Add GeoPermissions exception on synchronous geo permissions error fro…
Browse files Browse the repository at this point in the history
…m server
  • Loading branch information
mohsin-plivo committed Feb 18, 2025
1 parent d59b0e8 commit 8e6fcb9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Change Log
## [4.61.3](https://github.com/plivo/plivo-ruby/tree/v4.61.3) (2025-02-18)
**Feature - Throw GeoPermissionsError Exception on synchronous geo permissions error**

## [4.61.2](https://github.com/plivo/plivo-ruby/tree/v4.61.2)(2024-10-23)
**Feature - FraudCheck param in Create, Get and List Session**
- Support for the `fraud_check` parameter in sms verify session request
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The Plivo Ruby SDK makes it simpler to integrate communications into your Ruby a
Add this line to your application's Gemfile:

```ruby
gem 'plivo', '>= 4.61.2'
gem 'plivo', '>= 4.61.3'
```

And then execute:
Expand Down
12 changes: 10 additions & 2 deletions lib/plivo/base_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class BaseClient
# Base stuff
attr_reader :headers, :auth_credentials
@@voice_retry_count = 0
GEO_PERMISSION_ENDPOINTS = ['/Message/', '/Session/', '/Call/'].freeze
def initialize(auth_id = nil, auth_token = nil, proxy_options = nil, timeout=5)
configure_credentials(auth_id, auth_token)
configure_proxies(proxy_options)
Expand All @@ -26,7 +27,7 @@ def auth_id
end

def process_response(method, response)
handle_response_exceptions(response)
handle_response_exceptions(response, method)
if method == 'DELETE'
if !([200, 204].include? response[:status])
raise Exceptions::PlivoRESTError, "Resource at #{response[:url]} "\
Expand Down Expand Up @@ -341,7 +342,7 @@ def send_delete(resource_path, data, timeout, options = nil)
response
end

def handle_response_exceptions(response)
def handle_response_exceptions(response, method)
exception_mapping = {
400 => [
Exceptions::ValidationError,
Expand Down Expand Up @@ -373,6 +374,13 @@ def handle_response_exceptions(response)
]
}

if response[:status] == 403 && method == 'POST' && GEO_PERMISSION_ENDPOINTS.any? { |endpoint| response[:url].to_s.end_with?(endpoint) }
exception_mapping[403] = [
Exceptions::GeoPermissionsError,
'Geo-permission to the destination country is not enabled'
]
end

response_json = response[:body]
return unless exception_mapping.key?(response[:status])

Expand Down
4 changes: 4 additions & 0 deletions lib/plivo/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,9 @@ module Exceptions
##
# This will be raised when there is an authentication error
ResourceNotFoundError = Class.new(PlivoRESTError)

##
# This will be raised when the destination country is not enabled for sms/voice
GeoPermissionsError = Class.new(PlivoRESTError)
end
end
2 changes: 1 addition & 1 deletion lib/plivo/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Plivo
VERSION = "4.61.2".freeze
VERSION = "4.61.3".freeze
end

0 comments on commit 8e6fcb9

Please sign in to comment.