Skip to content

Commit

Permalink
Return a simple dict indicating there was an error with the request.
Browse files Browse the repository at this point in the history
An error at the request stage usually would indicate authorization problems.

It could be other things though.

TODO: Write more versatile exception handling related to the request
  • Loading branch information
jgillmanjr committed Oct 30, 2014
1 parent 1619b6a commit ca75a0f
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions snakeStorm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,16 @@ def request(self, parameters, apiMethod):
""" Send the request to the Storm API. """
method = self.lastMethod = apiMethod
fullURI = self.lastURI = '%s:%s/%s/%s.%s' % (self.baseURI, str(self.apiPort), self.version, method, self.apiFormat)
## Do we have params or not? ##
if len(parameters) > 0: # We have parameters - make a POST
postData = {}
postData['params'] = self.lastParams = parameters
self.lastResult = requests.post(fullURI, data = json.dumps(postData), auth = (self.username, self.password), verify = self.verify).json()
else: # No parameters - make a GET
self.lastResult = requests.request('GET', fullURI, auth = (self.username, self.password), verify = self.verify).json()
try:
## Do we have params or not? ##
if len(parameters) > 0: # We have parameters - make a POST
postData = {}
postData['params'] = self.lastParams = parameters
self.lastResult = requests.post(fullURI, data = json.dumps(postData), auth = (self.username, self.password), verify = self.verify).json()
else: # No parameters - make a GET
self.lastResult = requests.request('GET', fullURI, auth = (self.username, self.password), verify = self.verify).json()
except Exception as e:
self.lastResult = {'snakeStormError': 'There was an error with the request. Check your credentials?'}

return self.lastResult

Expand Down

0 comments on commit ca75a0f

Please sign in to comment.