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

fastpi: return error responses formatted for the connectrpc protocol #77

Merged
merged 2 commits into from
Feb 20, 2024

Conversation

achille-roussel
Copy link
Contributor

This PR changes the FastAPI adapter to return error responses in the format expected by the Connect protocol (see https://connectrpc.com/docs/protocol/#error-end-stream).

All errors will now be reported as a http response with a non-200 status code, and a JSON body with this shape:

{
  "code": "...",
  "message": "..."
}

Two status codes are now reserved to indicate issues with http request signatures:

  • 401 for the ValueError raised when the signature uses an unsupported hashing algorithm or when it didn't contain all the expected attributes (these should never occur when connected to the Dispatch platform)
  • 403 for any other verification failures related to the signing keys

Signed-off-by: Achille Roussel <achille.roussel@gmail.com>
@achille-roussel achille-roussel added the bug Something isn't working label Feb 20, 2024
@achille-roussel achille-roussel self-assigned this Feb 20, 2024
Signed-off-by: Achille Roussel <achille.roussel@gmail.com>
@achille-roussel achille-roussel merged commit 4624d5f into main Feb 20, 2024
3 checks passed
@achille-roussel achille-roussel deleted the fix-fastapi-error-responses branch February 20, 2024 01:34
achille-roussel added a commit to dispatchrun/dispatch-proto that referenced this pull request Feb 20, 2024
This PR documents HTTP status codes used by
dispatchrun/dispatch-py#77 and the
format of error response payloads.
@pelletier pelletier changed the title FastAPI: return error responses formatted for the connectrpc protocol fastpi: return error responses formatted for the connectrpc protocol Feb 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants