-
Notifications
You must be signed in to change notification settings - Fork 7
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
Catch certain errors in the API and return information about them as response #186
Merged
Conversation
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
matthiasschaub
force-pushed
the
api-error-msg
branch
from
October 4, 2021 05:50
9061d0d
to
f012f34
Compare
matthiasschaub
commented
Oct 4, 2021
matthiasschaub
added
the
comments welcome
Indicates that the creator of this PR is open for early review comments
label
Oct 4, 2021
matthiasschaub
force-pushed
the
api-error-msg
branch
from
October 24, 2021 13:27
f012f34
to
9de26f8
Compare
matthiasschaub
force-pushed
the
api-error-msg
branch
5 times, most recently
from
October 26, 2021 05:42
2b1b1c9
to
91c5c39
Compare
matthiasschaub
removed
the
comments welcome
Indicates that the creator of this PR is open for early review comments
label
Oct 27, 2021
matthiasschaub
force-pushed
the
api-error-msg
branch
2 times, most recently
from
October 29, 2021 04:33
9e1c84a
to
845d15d
Compare
joker234
reviewed
Oct 29, 2021
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.
👍 some minor remarks ;)
workers/tests/integrationtests/fixtures/ohsome-response-200-invalid.geojson
Outdated
Show resolved
Hide resolved
workers/tests/integrationtests/test_api_indicator_geojson_io.py
Outdated
Show resolved
Hide resolved
parameter in pydantic request model.
when the input is a Feature Collection. Either Feature id field if present or otherwise the enumeration variable.
geometry and return information about this error as API response.
FastAPIs `RequestValidationError` is a subclass of pydantics `ValidationError`. Because of the usage of `@pydantic.validate_arguments` decorator `ValidationError` needs to be specified in the FastAPI exception handler as well.
Refactor out AsyncMock class to utils.py because it is used in multiple modules.
block is empty. This will also avoid SonarCloud error.
matthiasschaub
force-pushed
the
api-error-msg
branch
from
October 29, 2021 15:25
bbce00d
to
699e75e
Compare
matthiasschaub
force-pushed
the
api-error-msg
branch
from
October 29, 2021 15:48
2543bd9
to
888c6e6
Compare
matthiasschaub
force-pushed
the
api-error-msg
branch
from
October 29, 2021 15:49
888c6e6
to
a89a3b8
Compare
unittests directory instead of integrationtests directory.
joker234
previously approved these changes
Oct 29, 2021
matthiasschaub
force-pushed
the
api-error-msg
branch
from
October 29, 2021 16:16
759ea38
to
12f683f
Compare
joker234
approved these changes
Oct 29, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Per default errors which arise during validation of an API request (
pydantic
models) are caught by FastAPI and details are returned in the API response (ReqestValidationError
). Cases covered by this are:This PR will extend the numbers of errors about which FastAPI will return details.
In particular it will add custom exception handlers to FastAPI (FastAPI docs). Thise will cover two more cases:
SizeRestrictionError
: bpolys exceeds geometry size limitIn addition this PR seeks to unify the response schema for errors raised during API request parameter validation (
pydatic
models) and those covered by the custom exception handlers. This is not as straightforward as it sounds since theReqestValidationError
contains information about multiple errors ("One exception will be raised regardless of the number of errors found, that ValidationError will contain information about all the errors and how they happened." (pydantic docs). In effect to each response only the error type is added.Current response schema for custom errors:
Current response schema for validation errors:
Changed response schema for custom errors:
Changed response schema for custom errors:
Open Issues
This should probably be its own PR -> #207:
feature.id
in each error message.Corresponding issue
Closes #107
Related #103
Checklist
main
(e.g. throughgit rebase main
)