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

Transport error mode for server HTTP and GRPC APIs #690

Merged
merged 4 commits into from
Oct 9, 2023

Conversation

FZambia
Copy link
Member

@FZambia FZambia commented Aug 19, 2023

Proposed changes

Currently Centrifugo server API never returns transport level errors - for example it always returns 200 OK for HTTP API and never returns GRPC transport-level errors.

This PR adds an option to use transport-native error codes instead of Centrifugo error field in response. The motivation is make API friendly to integrate with network ecosystem - for automatic retries, better logging, etc.

In current state PR does not modify Batch and Broadcast APIs which are quite special. For these two calls we can't introduce transport-level errors as the response actually includes results of different independent command execution. Most probably the best we can do is documenting this distinction.

Behaviour may be turned on globally:

  • using "api_error_mode": "transport" for HTTP
  • or "grpc_api_error_mode": "transport" for GRPC

Also it may be used on per-request basis:

  • by setting custom header X-Centrifugo-Error-Mode: transport for HTTP
  • Adding custom metadata key x-centrifugo-error-mode: transport for GRPC

Example

Before:

echo '{}' | http POST "http://localhost:8000/api/publish"
HTTP/1.1 200 OK
Content-Length: 46
Content-Type: application/json
Date: Sat, 19 Aug 2023 07:23:40 GMT

{
    "error": {
        "code": 107,
        "message": "bad request"
    }
}

After:

echo '{}' | http POST "http://localhost:8000/api/publish" "X-Centrifugo-Error-Mode: transport"
HTTP/1.1 400 Bad Request
Content-Length: 36
Content-Type: application/json
Date: Sat, 19 Aug 2023 07:23:59 GMT

{
    "code": 107,
    "message": "bad request"
}

@FZambia FZambia changed the title Transport error mode for server API Transport error mode for server HTTP and GRPC APIs Aug 19, 2023
@FZambia FZambia merged commit f50f39e into master Oct 9, 2023
4 checks passed
@FZambia FZambia deleted the api_transport_error_mode branch October 9, 2023 18:36
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.

1 participant