From 9be4b95f3905d35b2c6ba5cdbe521f21b770f008 Mon Sep 17 00:00:00 2001 From: Malkin0xb Date: Thu, 25 Jul 2024 16:55:21 +0100 Subject: [PATCH 1/4] Returns empty dict if user or group doesnt have license --- odins_spear/exceptions.py | 9 ++++++++- odins_spear/methods/get.py | 18 +++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/odins_spear/exceptions.py b/odins_spear/exceptions.py index 6198972..4bbfbd1 100644 --- a/odins_spear/exceptions.py +++ b/odins_spear/exceptions.py @@ -121,4 +121,11 @@ class OSFileNotFound(OSError): """ def __str__(self) -> str: - return f"File can not be found, please check path and file name." \ No newline at end of file + return f"File can not be found, please check path and file name." + +class OSLicenseNonExistent(OSError): + """ Raised when the Specified Entity doesn't exist due to licensing. + """ + + def __str__(self) -> str: + return f"Specified Entity doesn't have the correct License." \ No newline at end of file diff --git a/odins_spear/methods/get.py b/odins_spear/methods/get.py index 0cba597..3b00e2f 100644 --- a/odins_spear/methods/get.py +++ b/odins_spear/methods/get.py @@ -1,4 +1,5 @@ from ..utils.formatting import format_filter_value +from ..exceptions import * class Get(): @@ -139,8 +140,13 @@ def user_call_center(self, user_id: str): params = { "userId": user_id } - - return self.requester.get(endpoint, params=params) + try: + self.requester.get(endpoint, params=params) + except Exception as error: # If user is not found + if "404" in str(error): + return dict([]) # Return empty dict + else: + return def group_call_center_bounced_calls(self, service_user_id: str): @@ -178,7 +184,13 @@ def group_call_center_forced_forwarding(self, service_user_id: str): "serviceUserId": service_user_id } - return self.requester.get(endpoint, params=params) + try: + self.requester.get(endpoint, params=params) + except Exception as error: # If service is not found + if "404" in str(error): + return dict([]) # Return empty dict + else: + return def group_call_center_overflow(self, service_user_id): From bab1a4234ce749a311036162dfc05e685417fcdc Mon Sep 17 00:00:00 2001 From: Malkin0xb Date: Thu, 25 Jul 2024 16:56:57 +0100 Subject: [PATCH 2/4] Remove exception import --- odins_spear/methods/get.py | 1 - 1 file changed, 1 deletion(-) diff --git a/odins_spear/methods/get.py b/odins_spear/methods/get.py index 3b00e2f..882bb03 100644 --- a/odins_spear/methods/get.py +++ b/odins_spear/methods/get.py @@ -1,5 +1,4 @@ from ..utils.formatting import format_filter_value -from ..exceptions import * class Get(): From 90d34e09bcfaf13abb0c47d6954fe713fb55c68c Mon Sep 17 00:00:00 2001 From: Malkin0xb Date: Fri, 9 Aug 2024 12:16:47 +0100 Subject: [PATCH 3/4] Update user_call_center() error handling --- odins_spear/methods/get.py | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/odins_spear/methods/get.py b/odins_spear/methods/get.py index 882bb03..d9b7ab6 100644 --- a/odins_spear/methods/get.py +++ b/odins_spear/methods/get.py @@ -1,5 +1,5 @@ from ..utils.formatting import format_filter_value - +from ..exceptions import * class Get(): @@ -140,12 +140,12 @@ def user_call_center(self, user_id: str): "userId": user_id } try: - self.requester.get(endpoint, params=params) - except Exception as error: # If user is not found - if "404" in str(error): - return dict([]) # Return empty dict + import requests.exceptions + response = self.requester.get(endpoint, params=params) + except requests.exceptions.HTTPError: + raise OSLicenseNonExistent else: - return + return response def group_call_center_bounced_calls(self, service_user_id: str): @@ -183,14 +183,8 @@ def group_call_center_forced_forwarding(self, service_user_id: str): "serviceUserId": service_user_id } - try: - self.requester.get(endpoint, params=params) - except Exception as error: # If service is not found - if "404" in str(error): - return dict([]) # Return empty dict - else: - return - + return self.requester.get(endpoint, params=params) + def group_call_center_overflow(self, service_user_id): """Retrieves the forwarding number for a user when all call center agents are busy, along with any associated audio messages. From cda661c1a07ca3425564cc059690f5356b0164ae Mon Sep 17 00:00:00 2001 From: Malkin0xb Date: Fri, 9 Aug 2024 12:19:58 +0100 Subject: [PATCH 4/4] Use RequestException --- odins_spear/methods/get.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/odins_spear/methods/get.py b/odins_spear/methods/get.py index d9b7ab6..92c158c 100644 --- a/odins_spear/methods/get.py +++ b/odins_spear/methods/get.py @@ -142,7 +142,7 @@ def user_call_center(self, user_id: str): try: import requests.exceptions response = self.requester.get(endpoint, params=params) - except requests.exceptions.HTTPError: + except requests.exceptions.RequestException: raise OSLicenseNonExistent else: return response