Spring 如何使用特使代理在Grpc中以json形式发送错误响应
我使用resonseObservator.onError从grpc服务抛出错误,但在从REST客户端点击REST API时,我没有得到json格式的消息,尽管积极的场景工作正常,并以json形式给出响应 我使用特使作为转码器,有谁能帮助我如何获得错误响应(也作为json)。目前我收到错误场景的错误请求。该项目在SpringBoot中进行 TIA您可以使用convert\u grpc\u status:true来执行此操作Spring 如何使用特使代理在Grpc中以json形式发送错误响应,spring,spring-boot,grpc,grpc-java,envoyproxy,Spring,Spring Boot,Grpc,Grpc Java,Envoyproxy,我使用resonseObservator.onError从grpc服务抛出错误,但在从REST客户端点击REST API时,我没有得到json格式的消息,尽管积极的场景工作正常,并以json形式给出响应 我使用特使作为转码器,有谁能帮助我如何获得错误响应(也作为json)。目前我收到错误场景的错误请求。该项目在SpringBoot中进行 TIA您可以使用convert\u grpc\u status:true来执行此操作 http_filters: - name: env
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
如果您的意思是像这样返回详细信息键:
{
"code": 3,
"message": "API call quota depleted",
"details": [
{
"@type": "type.googleapis.com/google.rpc.ResourceInfo",
"resourceType": "xxxxxx",
"resourceName": "",
"owner": "",
"description": ""
}
]
}
您必须使用以下命令编译.proto文件:
import "google/rpc/error_details.proto";
因为如果没有错误类型,特使无法从后端服务器反序列化二进制详细信息
此外,您还可以阅读如何使用Python发送详细的错误响应:您可能希望在上进行后续操作。我注意到@SanP有一个相关问题,我遇到了这个错误,无法将JSON解析为proto INVALID_参数:convert_grpc_status:找不到字段。