Skip to content

Commit

Permalink
- distinguish return code between authentication failure and other fa…
Browse files Browse the repository at this point in the history
…ilures when connecting to postgres database, when deleting a database

- return status code in other cases of failures, too
  • Loading branch information
Jonas Weismueller committed Aug 6, 2018
1 parent 45125d4 commit 569dc71
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions postgraas_server/management_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ def delete(self, id):
):
pass
except Exception as ex:
return_code = 401 if 'authentication failed' in str(ex) else 500
return {
'status': 'failed',
'msg': 'Could not connect to postgres instance: {}'.format(str(ex))
}, 401
}, return_code

if not current_app.postgraas_backend.exists(entity):
logger.warning(
Expand All @@ -108,7 +109,7 @@ def delete(self, id):
current_app.postgraas_backend.delete(entity)
except PostgraasApiException as e:
logger.warning("error deleting container {}: {}".format(entity.container_id, str(e)))
return {'status': 'failed', 'msg': str(e)}
return {'status': 'failed', 'msg': str(e)}, 500
db.session.delete(entity)
db.session.commit()
return {'status': 'success', 'msg': 'deleted postgraas instance'}
Expand Down Expand Up @@ -172,7 +173,7 @@ def post(self):
try:
db_entry.container_id = current_app.postgraas_backend.create(db_entry, db_credentials)
except PostgraasApiException as e:
return {'msg': str(e)}
return {'msg': str(e)}, 500

if '@' not in args['db_username']:
try:
Expand Down

0 comments on commit 569dc71

Please sign in to comment.