-
Notifications
You must be signed in to change notification settings - Fork 7
Make ApiUsageException return a more appropriate response code #4396
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
Draft
labkey-tchad
wants to merge
7
commits into
develop
Choose a base branch
from
fb_apiUsage422
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9d04973
Make `ApiUsageException` return a more appropriate response code
labkey-tchad e94eb3e
Make `ApiUsageException` extend BadRequestException
labkey-tchad f0f836a
Merge remote-tracking branch 'origin/develop' into fb_apiUsage422
labkey-tchad 1d2331f
Merge remote-tracking branch 'origin/develop' into fb_apiUsage422
labkey-tchad 3994004
Use HttpStatus constants instead of integers
labkey-tchad 160f37a
GWT class can't reference HttpStatus
labkey-tchad ec08035
Merge remote-tracking branch 'origin/develop' into fb_apiUsage422
labkey-tchad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think defaulting to a 422 seems best, and cases that should return a 404 can be switched to use
NotFoundException
.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.
What a mess. A lot of usages of ApiUsageException do indeed seem equally or better served by NotFoundException or ValidationException.
I like the move to 4xx responses. I do not like using 400 BAD_REQUEST for any request that is basically well formatted but we can't handle for an explainable reason (e.g. Validation, NotFound, Unauthorized).
Separately, but not a topic for today. If I could design this all over again, I would use 200 {success:false} for most of our error cases and reserve non 200 responses for actual protocol errors (e.g. this isn't an legal end point so NOT_FOUND, rather than I can't find that rowid).
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.
I disagree. I think we should try to respond with the appropriate HTTP codes as intended. For example, 404:
404 doesn't indicate that the end point is illegal but rather that the resource was not found. Not finding the thing with "rowId" is precisely the case it is intended to cover.
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.
Thank you for taking a look at this. When I have some spare cycles, I'll take a crack at switching
ApiUsageException
to return a 422 and switching around some inappropriate usages.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.
I'm a bit ambivalent about the 404 case. I still think that generally any interaction where "I got your request", "I understood your request", "Here's my response to your request" doesn't require out of band error handling.
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.
Certainly agree that the "out of band error handling" is not the ideal way to process this kind of thing.
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.
The latest wording for a 400 error is a little less specific to malformed requests:
something that is perceived to be a client error
-- compared to the original wording:The request could not be understood by the server due to malformed syntax
.422 was added as a WebDAV specific response code but has since been pulled into the core HTTP standard.
That being said, I'm inclined to move forward with 422 for
ApiUsageException
. That's what the GitHub API returns for requests that it understands but have some semantic error (e.g. missing a required field).