-
Notifications
You must be signed in to change notification settings - Fork 0
Add error handling to the API blueprint. #40
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
Open
scolby33
wants to merge
18
commits into
develop
Choose a base branch
from
error-handling
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.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
60b9e20
Add error handling to /register API endpoint.
scolby33 5a5d3a0
Add :raises: to docstrings where appropriate.
scolby33 7901d13
Ignore McCabe complexity on register_location_key.
scolby33 92b4709
Add more error checking to the API.
scolby33 a686985
Ignore McCabe complexity on submit.
scolby33 b0defea
Switch to using an Exception instead of manually calling abort()
scolby33 6318848
Remove some print() debugging. Sorry @cthoyt
scolby33 83b2850
Fancier error messages for the API.
scolby33 e9e86e9
Add `status` key to the response JSON of InvalidUsage exception.
scolby33 2cbb4c9
Broken client_session fixture first try.
scolby33 efbf402
Style fixes.
scolby33 e6a19d6
Add the ability to do tests on the Flask portion of OCSPdash.
scolby33 a67cb91
Since this static method is kinda generic, use a more generic return …
scolby33 cc4281f
Update type hints and documentation
cthoyt 5d4cf22
Remove unnecessary default
cthoyt e5eea9a
Combine logic
cthoyt bb2b14a
Add function to make some test data
cthoyt fcfdcee
Address TODOs
cthoyt 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # -*- coding: utf-8 -*- | ||
|
|
||
| """Exceptions and Errors for the OCSPdash web package.""" | ||
|
|
||
| from http import HTTPStatus | ||
| from typing import Mapping | ||
|
|
||
|
|
||
| class InvalidUsage(Exception): | ||
| """An Exception to be raised by a view for invalid usage of the endpoint.""" | ||
|
|
||
| status_code = HTTPStatus.BAD_REQUEST | ||
|
|
||
| def __init__(self, message: str, status_code: HTTPStatus=None, payload: Mapping=None) -> None: | ||
| """Create an InvalidUsage exception. | ||
|
|
||
| :param message: The message for the exception; will be placed in the `message` key of the JSON returned in the response. | ||
| :param status_code: An HTTP status code for the response; default is 400 BAD REQUEST. It will also be placed in the `status` key of the returned JSON. | ||
| :param payload: A mapping that can be jsonified by Flask; will be returned as JSON in the response alongside the message. | ||
| """ | ||
| super().__init__(self) | ||
| self.message = message | ||
| if status_code is not None: | ||
| self.status_code = status_code | ||
| self.payload = payload | ||
|
|
||
| def to_json(self) -> Mapping: | ||
| """Return a representation of the exception suitable to passed for JSON conversion.""" | ||
| rv = dict(self.payload or ()) | ||
| rv['message'] = self.message | ||
| rv['status'] = self.status_code | ||
| return rv |
This file contains hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Are these vexing exceptions? @cthoyt
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, since it doesn't mean your code has been designed wrong, but rather you have to deal with the reality that someone else is going to stick weird shit inside as the invite token.
Now, the next exception checking for the expiration of the pubkey might be different, but raising an exception actually makes the logic for using this function much better. Overall, I like this design and I think it does what it's supposed to in an elegant way. Lots of helpful/useful errors for bad situations where the program should stop seems good to me.