1414from bandwidth .twofactorauth .models .two_factor_voice_response import TwoFactorVoiceResponse
1515from bandwidth .twofactorauth .models .two_factor_messaging_response import TwoFactorMessagingResponse
1616from bandwidth .twofactorauth .models .two_factor_verify_code_response import TwoFactorVerifyCodeResponse
17- from bandwidth .twofactorauth .exceptions .invalid_request_exception import InvalidRequestException
17+ from bandwidth .twofactorauth .exceptions .error_with_request_exception import ErrorWithRequestException
18+ from bandwidth .twofactorauth .exceptions .unauthorized_request_exception import UnauthorizedRequestException
19+ from bandwidth .twofactorauth .exceptions .forbidden_request_exception import ForbiddenRequestException
1820
1921
20- class APIController (BaseController ):
22+ class MFAController (BaseController ):
2123
2224 """A Controller to access Endpoints in the bandwidth API."""
2325
2426 def __init__ (self , config , call_back = None ):
25- super (APIController , self ).__init__ (config , call_back )
27+ super (MFAController , self ).__init__ (config , call_back )
2628
2729 def create_voice_two_factor (self ,
2830 account_id ,
2931 body ):
3032 """Does a POST request to /accounts/{accountId}/code/voice.
3133
32- Two-Factor authentication with Bandwidth Voice services
34+ Allows a user to send a MFA code through a phone call
3335
3436 Args:
3537 account_id (string): Bandwidth Account ID with Voice service
@@ -71,7 +73,13 @@ def create_voice_two_factor(self,
7173
7274 # Endpoint and global error handling using HTTP status codes.
7375 if _response .status_code == 400 :
74- raise InvalidRequestException ('client request error' , _response )
76+ raise ErrorWithRequestException ('If there is any issue with values passed in by the user' , _response )
77+ elif _response .status_code == 401 :
78+ raise UnauthorizedRequestException ('Authentication is either incorrect or not present' , _response )
79+ elif _response .status_code == 403 :
80+ raise ForbiddenRequestException ('The user is not authorized to access this resource' , _response )
81+ elif _response .status_code == 500 :
82+ raise ErrorWithRequestException ('An internal server error occurred' , _response )
7583 self .validate_response (_response )
7684
7785 decoded = APIHelper .json_deserialize (_response .text , TwoFactorVoiceResponse .from_dictionary )
@@ -83,7 +91,7 @@ def create_messaging_two_factor(self,
8391 body ):
8492 """Does a POST request to /accounts/{accountId}/code/messaging.
8593
86- Two-Factor authentication with Bandwidth messaging services
94+ Allows a user to send a MFA code through a text message (SMS)
8795
8896 Args:
8997 account_id (string): Bandwidth Account ID with Messaging service
@@ -125,7 +133,13 @@ def create_messaging_two_factor(self,
125133
126134 # Endpoint and global error handling using HTTP status codes.
127135 if _response .status_code == 400 :
128- raise InvalidRequestException ('client request error' , _response )
136+ raise ErrorWithRequestException ('If there is any issue with values passed in by the user' , _response )
137+ elif _response .status_code == 401 :
138+ raise UnauthorizedRequestException ('Authentication is either incorrect or not present' , _response )
139+ elif _response .status_code == 403 :
140+ raise ForbiddenRequestException ('The user is not authorized to access this resource' , _response )
141+ elif _response .status_code == 500 :
142+ raise ErrorWithRequestException ('An internal server error occurred' , _response )
129143 self .validate_response (_response )
130144
131145 decoded = APIHelper .json_deserialize (_response .text , TwoFactorMessagingResponse .from_dictionary )
@@ -137,7 +151,7 @@ def create_verify_two_factor(self,
137151 body ):
138152 """Does a POST request to /accounts/{accountId}/code/verify.
139153
140- Verify a previously sent two-factor authentication code
154+ Allows a user to verify an MFA code
141155
142156 Args:
143157 account_id (string): Bandwidth Account ID with Two-Factor enabled
@@ -178,7 +192,15 @@ def create_verify_two_factor(self,
178192
179193 # Endpoint and global error handling using HTTP status codes.
180194 if _response .status_code == 400 :
181- raise InvalidRequestException ('client request error' , _response )
195+ raise ErrorWithRequestException ('If there is any issue with values passed in by the user' , _response )
196+ elif _response .status_code == 401 :
197+ raise UnauthorizedRequestException ('Authentication is either incorrect or not present' , _response )
198+ elif _response .status_code == 403 :
199+ raise ForbiddenRequestException ('The user is not authorized to access this resource' , _response )
200+ elif _response .status_code == 429 :
201+ raise ErrorWithRequestException ('The user has made too many bad requests and is temporarily locked out' , _response )
202+ elif _response .status_code == 500 :
203+ raise ErrorWithRequestException ('An internal server error occurred' , _response )
182204 self .validate_response (_response )
183205
184206 decoded = APIHelper .json_deserialize (_response .text , TwoFactorVerifyCodeResponse .from_dictionary )
0 commit comments