1

Let's say I am working in ServiceA which calls ServiceB. Now if ServiceB returns NotFound, AlreadyExists or InvalidArgument error codes, what should we return to the caller of ServiceA?

  1. Based on documentation to gRPC error code, it looks like Internal is what we should return if

    invariants expected by the underlying system have been broken

    I am not very sure what this bold text means, does it mean any downstream error should be returned as Internal error code?

  2. For example, NotFound documentation says:

    NotFound means some requested entity (e.g., file or directory) was not found

    Does that mean we should parse the downstream error and return NotFoundto the caller of ServiceA if ServiceB returns NotFound?

4

1 回答 1

1

您为端点返回的状态代码ServiceA应该对调用者有意义。您的业​​务逻辑应该规定应该为下游错误返回什么状态代码。通过下游服务的代码返回可能是有意义的,但并非总是如此。

考虑您实现一个从和从getUserDetails调用的端点的情况。getUserUserServicegetRatingsRatingService

  1. 如果getUser返回NotFound ,那么将NotFound返回给调用者也是有意义的,因为用户不存在。
  2. 如果getRatings返回NotFound,您可以返回一个内部错误,因为您没有足够的信息来返回完整的响应。在这种情况下,如果您返回NotFound,客户端可能会假设未找到用户,但事实并非如此。
于 2020-04-06T19:10:40.757 回答