我想為我的 REST API 使用 google.golang.org/grpc/status 錯誤模型,因為它說您可以:該Status類型定義了適用于不同編程環境的邏輯錯誤模型,包括 REST API 和 RPC API。但是我遇到details了結構部分的問題。我知道它是 type []*anypb.Any,但是,我不清楚如何將它變成“解包”形式,因此我可以看到 Field 和 Description 屬性,而不是 base64 編碼的value字段。我得到了什么:{ "code": 3, "message": "One or more fields are invalid", "details": [ { "type_url": "type.googleapis.com/google.rpc.BadRequest.FieldViolation", "value": "CgVFbWFpbBIUSW52YWxpZCBlbWFpbCBmb3JtYXQ=" }, { "type_url": "type.googleapis.com/google.rpc.BadRequest.FieldViolation", "value": "CghQYXNzd29yZBIeTXVzdCBiZSBhdCBsZWFzdCAxMCBjaGFyYWN0ZXJz" } ]}我應該得到什么:{ "code": 3, "message": "One or more fields are invalid", "details": [ { "type_url": "type.googleapis.com/google.rpc.BadRequest.FieldViolation", "field": "Email", "description": "Invalid email format" }, { "type_url": "type.googleapis.com/google.rpc.BadRequest.FieldViolation", "field": "Password", "description": "Must be at least 10 characters" } ]}
- 1 回答
- 0 關注
- 146 瀏覽
添加回答
舉報
0/150
提交
取消