-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactored Client.parse method, new custom error class, now returning…
… full error details, fixing all tests...
- Loading branch information
Showing
13 changed files
with
182 additions
and
870 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,117 @@ | ||
class ClientError(Exception): | ||
pass | ||
from requests import Response | ||
|
||
|
||
class ServerError(Exception): | ||
pass | ||
class VonageError(Exception): | ||
"""Base Error Class for all Vonage SDK errors.""" | ||
|
||
|
||
class ServerError(VonageError): | ||
"""Indicates an error was reported from a Vonage server.""" | ||
|
||
|
||
class ClientError(VonageError): | ||
"""Indicates an error was recieved as part of the response from a Vonage SDK request.""" | ||
|
||
def __init__(self, response: Response, content_type: str, host: str): | ||
if content_type == 'application/json': | ||
self.body = response.json() | ||
else: | ||
self.body = response.text | ||
if self.body: | ||
super().__init__( | ||
f'{response.status_code} response from {host}. \nError Message:\n{self.body}' | ||
) | ||
else: | ||
super().__init__(f'{response.status_code} response from {host}.') | ||
|
||
|
||
class AuthenticationError(ClientError): | ||
class AuthenticationError(VonageError): | ||
pass | ||
|
||
|
||
class CallbackRequiredError(ClientError): | ||
class CallbackRequiredError(VonageError): | ||
"""Indicates a callback is required but was not present.""" | ||
|
||
|
||
class MessagesError(ClientError): | ||
class MessagesError(VonageError): | ||
""" | ||
Indicates an error related to the Messages class which calls the Vonage Messages API. | ||
""" | ||
|
||
|
||
class SmsError(ClientError): | ||
class SmsError(VonageError): | ||
""" | ||
Indicates an error related to the Sms class which calls the Vonage SMS API. | ||
""" | ||
|
||
|
||
class PartialFailureError(ClientError): | ||
class PartialFailureError(VonageError): | ||
""" | ||
Indicates that one or more parts of the message was not sent successfully. | ||
""" | ||
|
||
|
||
class PricingTypeError(ClientError): | ||
class PricingTypeError(VonageError): | ||
"""A pricing type was specified that is not allowed.""" | ||
|
||
|
||
class InvalidAuthenticationTypeError(ClientError): | ||
class InvalidAuthenticationTypeError(VonageError): | ||
"""An authentication method was specified that is not allowed.""" | ||
|
||
|
||
class InvalidRoleError(ClientError): | ||
class InvalidRoleError(VonageError): | ||
"""The specified role was invalid.""" | ||
|
||
|
||
class TokenExpiryError(ClientError): | ||
class TokenExpiryError(VonageError): | ||
"""The specified token expiry time was invalid.""" | ||
|
||
|
||
class InvalidOptionsError(ClientError): | ||
class InvalidOptionsError(VonageError): | ||
"""The option(s) that were specified are invalid.""" | ||
|
||
"""An authentication method was specified that is not allowed.""" | ||
|
||
|
||
class VerifyError(ClientError): | ||
class VerifyError(VonageError): | ||
"""Error related to the Verify API.""" | ||
|
||
|
||
class BlockedNumberError(ClientError): | ||
class BlockedNumberError(VonageError): | ||
"""The number you are trying to verify is blocked for verification.""" | ||
|
||
|
||
class NumberInsightError(ClientError): | ||
class NumberInsightError(VonageError): | ||
"""Error related to the Number Insight API.""" | ||
|
||
|
||
class SipError(ClientError): | ||
class SipError(VonageError): | ||
"""Error related to usage of SIP calls.""" | ||
|
||
|
||
class InvalidInputError(ClientError): | ||
class InvalidInputError(VonageError): | ||
"""The input that was provided was invalid.""" | ||
|
||
|
||
class InvalidAuthenticationTypeError(ClientError): | ||
class InvalidAuthenticationTypeError(VonageError): | ||
"""An authentication method was specified that is not allowed.""" | ||
|
||
|
||
class MeetingsError(ClientError): | ||
class MeetingsError(VonageError): | ||
"""An error related to the Meetings class which calls the Vonage Meetings API.""" | ||
|
||
|
||
class Verify2Error(ClientError): | ||
class Verify2Error(VonageError): | ||
"""An error relating to the Verify (V2) API.""" | ||
|
||
|
||
class SubaccountsError(ClientError): | ||
class SubaccountsError(VonageError): | ||
"""An error relating to the Subaccounts API.""" | ||
|
||
|
||
class ProactiveConnectError(ClientError): | ||
class ProactiveConnectError(VonageError): | ||
"""An error relating to the Proactive Connect API.""" | ||
|
||
|
||
class UsersError(ClientError): | ||
class UsersError(VonageError): | ||
"""An error relating to the Users API.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.