1

I am throwing error from grpc service using resonseObserver.onError() but I am not getting messages in json format while hitting REST API from rest client, though the positive scenario is working fine and giving response as json.

I am using envoy as a transcoder, can anyone help me with how to get error response also as json. Currently I am getting BadRequest on error scenarios. The project is in SpringBoot.

TIA

Rohit Kotak
  • 173
  • 1
  • 17
  • You may want to follow it up at https://github.com/envoyproxy/envoy. I notice a related issue there https://github.com/envoyproxy/envoy/issues/8315 – San P May 27 '20 at 16:35
  • @SanP I am getting this error Unable to parse JSON as proto (INVALID_ARGUMENT:convert_grpc_status: Cannot find field.) – Rohit Kotak Jun 29 '20 at 18:00

1 Answers1

2

You can use convert_grpc_status: true for do this.

      http_filters:
      - name: envoy.filters.http.grpc_json_transcoder
        typed_config:
          "@type": type.googleapis.com/envoy.extensions.filters.http.grpc_json_transcoder.v3.GrpcJsonTranscoder
          proto_descriptor: "/tmp/envoy/proto.pb"
          services: ["xxxxxxxx"]
          convert_grpc_status: true
          print_options:
            always_print_primitive_fields: true
            always_print_enums_as_ints: false
            preserve_proto_field_names: false

If you mean return details key like this:

{
  "code": 3,
  "message": "API call quota depleted",
  "details": [
    {
      "@type": "type.googleapis.com/google.rpc.ResourceInfo",
      "resourceType": "xxxxxx",
      "resourceName": "",
      "owner": "",
      "description": ""
    }
  ]
}

You MUST compile you .proto file with:

import "google/rpc/error_details.proto";

because Envoy can't deserialize binary details from your backend server without error types.

Also you can read how you can send detailed error response with Python: How to send error details like as BadRequest

arturgspb
  • 1,004
  • 1
  • 12
  • 19