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

Increase role http error and test quality #222

Merged
merged 5 commits into from
Mar 15, 2024

Conversation

mikemrm
Copy link
Contributor

@mikemrm mikemrm commented Mar 8, 2024

This begins adding better request error handling.

Adds action validation checking against the policy before spending cycles hitting spicedb. This allows us to return better errors, 400's instead of 500's.

Also handles client disconnects gracefully. If the client disconnects, context canceled errors are captured and status is changed to 422's instead of an incorrect 500.

This also adds http tests for roles which resulted in the testauth package to simplify tests as auth is required in the http endpoints. This package will probably at some point be moved into the infratographer/x repo. But for now, while we develop the requirements it will be easier to develop it within the needed repo.

This updates access check requests to ensure the requested action exists
in the policy for the provided resource beforce executing the request to
spicedb and failing for this error.

Knowing this we can return a relevant error (ErrInvalidAction) which we
can now handle and return a 400 Bad Request status code instead of the
previous 500 Internal Server Error status code we were returning due to
the spicedb error we were receiving before.

Signed-off-by: Mike Mason <[email protected]>
@mikemrm mikemrm changed the title Begin handling more request errors better Begin handling request errors better Mar 8, 2024
Context Canceled errors from http requests should not produce 500 errors
as those are client requests.
This change adds an error middleware which can capture the canceled
context error and return a 422 status instead.

Signed-off-by: Mike Mason <[email protected]>
This validates create/update role action requests before submitting the
request to spicedb and handles the errors gracefully by returning 400
errors instead of generic 500 errors to the client.

Signed-off-by: Mike Mason <[email protected]>
@mikemrm mikemrm force-pushed the handle-request-errors branch 5 times, most recently from f6533cf to f258fc5 Compare March 11, 2024 18:12
@mikemrm mikemrm changed the title Begin handling request errors better Increase role http errors and test quality Mar 11, 2024
@mikemrm mikemrm changed the title Increase role http errors and test quality Increase role http error and test quality Mar 11, 2024
@mikemrm mikemrm marked this pull request as ready for review March 11, 2024 18:36
@mikemrm mikemrm requested review from a team as code owners March 11, 2024 18:36
This handles role http endpoint errors better by better handling the
errors returned and setting the response status codes.

Additionally this adds testing to the http api so we may test these http
status codes to ensure they are working as we expect.

Signed-off-by: Mike Mason <[email protected]>
This adds http tests and fixes the http status codes for the role
assignment and unassignment endpoints to resolve 500 errors occurring
when provided role ids were didn't exist.

Signed-off-by: Mike Mason <[email protected]>
switch errType {
case "":
case "echo":
return echo.ErrTeapot
Copy link
Contributor

Choose a reason for hiding this comment

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

🫖

@mikemrm mikemrm merged commit ca651fc into infratographer:main Mar 15, 2024
4 checks passed
@mikemrm mikemrm deleted the handle-request-errors branch March 15, 2024 14:30
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.

2 participants