Skip to content

Commit

Permalink
Additional error checking on API calls; See Scifabric#12
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmocracy committed Oct 4, 2017
1 parent 2d241f6 commit f458da9
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,11 @@ def find_project_by_short_name(short_name, pbclient, all=None):

def check_api_error(api_response):
"""Check if returned API response contains an error."""
if 'status' not in api_response:
msg = "Unable to find 'status' in server response; Misconfigured URL?"
print(msg)
print("Server response: %s" % api_response)
raise Exception(msg)
if type(api_response) == dict and (api_response.get('status') == 'failed'):
if 'ProgrammingError' in api_response.get('exception_cls'):
raise DatabaseError(message='PyBossa database error.',
Expand Down

0 comments on commit f458da9

Please sign in to comment.