Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return proper HTTP status codes, when deleting postgraas instances #31

Merged
4 commits merged into from
Aug 6, 2018

Conversation

ghost
Copy link

@ghost ghost commented Aug 3, 2018

No description provided.

@ghost ghost requested review from theMarix and sebastianneubauer August 3, 2018 13:25
@coveralls
Copy link

coveralls commented Aug 3, 2018

Coverage Status

Coverage increased (+0.08%) to 82.276% when pulling 44abcec on bugfix/delete-pg-instances-with-proper-http-status-codes into e265233 on master.

app.config['SQLALCHEMY_DATABASE_URI'] = get_meta_db_config_path(config)
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['BUNDLE_ERRORS'] = True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, what does this do?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

http://flask-restful.readthedocs.io/en/latest/reqparse.html#error-handling
It reports all errors found in the requests and reports all and not only the first one.

args = parser.parse_args()

entity = DBInstance.query.get(id)
if not entity:
return {'status': 'failed', 'msg': 'Postgraas instance {} does not exist'.format(id)}
return {'status': 'failed', 'msg': 'Postgraas instance {} does not exist'.format(id)}, 404
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in other cases we do abort(404, ...) not clear to me why or what the difference is, but at least we could harmonize it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK, strange, that they mix it up here, too:
http://flask-restful.readthedocs.io/en/latest/quickstart.html#full-example

abort(404, message="Todo {} doesn't exist".format(todo_id))

vs

return '', 204

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The difference is that abort raises an exception rather than simply returning something. It can therefore happen deep inside the call stack.

In the given context it does not really matter what we use. However, given that we already use abort for other error messages, I agree that abort will be more consistent.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it is ok in case of success (=2XX) to have return result, 201, and in all kinds of failure abort(500, ...). Just having some failures with return result, 400` and others with abort is strange.

@@ -91,7 +91,7 @@ def delete(self, id):
return {
'status': 'failed',
'msg': 'Could not connect to postgres instance: {}'.format(str(ex))
}
}, 401
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we have to differentiate here, 401 is only the correct status code, in case the authorization fail because of a wrong password. Most other exceptions should still give 500 imho

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe there is no easy way to differentiate between the different error classes without parsing exception texts. Maybe just using a generic 400 error here?

@ghost ghost requested review from StephanErb and removed request for theMarix August 6, 2018 08:49
Jonas Weismueller added 2 commits August 6, 2018 14:00
…ilures when connecting to postgres database, when deleting a database

- return status code in other cases of failures, too
Copy link
Member

@StephanErb StephanErb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@ghost ghost merged commit ca9981a into master Aug 6, 2018
@Fra-nk Fra-nk deleted the bugfix/delete-pg-instances-with-proper-http-status-codes branch January 28, 2019 10:18
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants