diff --git a/CHANGELOG.md b/CHANGELOG.md index 1cab55a..bd38fba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 795534e..bfb3031 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/lib/plivo/base_client.rb b/lib/plivo/base_client.rb index 5067373..27e926e 100644 --- a/lib/plivo/base_client.rb +++ b/lib/plivo/base_client.rb @@ -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) @@ -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]} "\ @@ -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, @@ -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]) diff --git a/lib/plivo/exceptions.rb b/lib/plivo/exceptions.rb index e2b1f04..eddef61 100644 --- a/lib/plivo/exceptions.rb +++ b/lib/plivo/exceptions.rb @@ -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 diff --git a/lib/plivo/version.rb b/lib/plivo/version.rb index a09f3cc..661e623 100644 --- a/lib/plivo/version.rb +++ b/lib/plivo/version.rb @@ -1,3 +1,3 @@ module Plivo - VERSION = "4.61.2".freeze + VERSION = "4.61.3".freeze end