-
Notifications
You must be signed in to change notification settings - Fork 8
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
Error payload #186
Error payload #186
Conversation
Current coverage is 88.69% (diff: 90.42%)@@ master #186 diff @@
==========================================
Files 36 37 +1
Lines 1275 1336 +61
Methods 0 0
Messages 0 0
Branches 121 129 +8
==========================================
+ Hits 1120 1185 +65
+ Misses 116 112 -4
Partials 39 39
|
Note that it's open to discussion if we should deliver a payloaded HTTPError for any exception that may occur. Right now, only REST exceptions produce an error that is potentially payloaded. Any other exception will produce a regular internal server error with no payload. |
@@ -37,6 +34,5 @@ Module contents | |||
|
|||
.. automodule:: remoteappmanager.db | |||
:members: | |||
:special-members: __init__ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes on the doc do not seem relevant to this PR, can you create an issue separately please?
Alternative to catching |
@kitchoi I already thought about that and I don't like it, because in write_error you have no knowledge of which methods was actually invoked. |
self.clear_header('Content-Type') | ||
self.finish() | ||
|
||
def rest_to_http_exception(self, rest_exc): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Class method for PayloadedHTTPError?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. In the future, the conversion will be done by a serializer that may produce xml instead of json. This serializer will be a instance var.
content_type = "text/plain" | ||
else: | ||
if content_type is not None: | ||
raise ValueError("Content type specified, but no payload") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this a problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would anyone say "application/json" and then provide no payload?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not what you would expect, but does it actually cause problem? If not, seem to be an unnecessary potential failure here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not unnecessary. The class constraints are clear. if you specify the payload, you can or cannot specify the content type. If you don't, it's by default text/plain. If you don't specify a payload, there's no reason for specifying the content type, and if you do, you are doing something very wrong, because it means that your payload is None by accident.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it wrong to set the header content-type to something but provide an empty content?
(by the way you could default payload
to an empty string, just an idea)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a difference between empty payload an no payload. some http responses don't want payload, and it's invalid if they do provide one (e.g. 204 No content, or 404 Not Found)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least in the context of REST, I mean. 404 can have a payload in non-rest context
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No payload but has content-type header - is it just because it is wrong in terms of definition or does it cause error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it causes an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you explain how please? I just wanted to understand.
Just a comment, instead of raising an Error, one could also call |
👍 |
Fixes #175
Missing tests. Will be added.