-
Notifications
You must be signed in to change notification settings - Fork 20
Open
Description
Hello,
I think most of json.loads(...)
should be replaced by self.parse_response(...)
def parse_response_without_exception(self, *args, **kwargs):
response = json.loads(*args, **kwargs)
return(response)
def parse_response_with_exception(self, *args, **kwargs):
response = json.loads(*args, **kwargs)
if 'errorCode' in response:
raise(Exception(response['errorCode']))
return(response)
so if an error message is returned it will raise an exception so it can be catch (or not)
if you want to keep current behaviour you should set inside __init__
self.parse_response = self.parse_response_without_exception
Moreover it will also allow user to easily monkey pach this code to redefine this parse_response
function.
I personally prefer to return Bunch
object instead of dict so my own parse_response
looks like
from bunch import Bunch, bunchify
def parse_response_with_exception(self, *args, **kwargs):
response = json.loads(*args, **kwargs)
if 'errorCode' in response:
raise(Exception(response['errorCode']))
return(bunchify(response))
Kind regards
Femto
Metadata
Metadata
Assignees
Labels
No labels