Skip to content
CCPEDIAby Unity Nodes
App Development

Error code on JSON API

3 posts353 viewsLast activity Jul 2022

  1. FrankieOP

    Hi there,

    With the new error code introduced since 1.18. Are they mapped to JSON API response as well? e.g. does the user get (DEADLINE_EXCEEDED - REQUEST_TIME_OUT), ( ABORTED - RESOURCE_EXHAUSTED) or ( UNAVAILABLE - INDEX_DB_SQL_TRANSIENT_ERROR) on JSON interface?

  2. Raymond_Roestenburg

    Hi Frankie,

    Yes, the com.google.rpc.Code error code is mapped to the JSON API response.

    DEADLINE_EXCEEDED maps to GATEWAY_OUT (504).
    ABORTED maps to CONFLICT (409)
    UNAVAILABLE maps to SERVICE_UNAVAILABLE (503)

    See the complete mapping below, from G (gRPC) to A (HTTP):

      case G.OK => A.OK
      case G.INVALID_ARGUMENT | G.FAILED_PRECONDITION | G.OUT_OF_RANGE => A.BadRequest
      case G.UNAUTHENTICATED => A.Unauthorized
      case G.PERMISSION_DENIED => A.Forbidden
      case G.NOT_FOUND => A.NotFound
      case G.ABORTED | G.ALREADY_EXISTS => A.Conflict
      case G.RESOURCE_EXHAUSTED => A.TooManyRequests
      case G.CANCELLED => ClientClosedRequest
      case G.DATA_LOSS | G.UNKNOWN | G.UNRECOGNIZED | G.INTERNAL => A.InternalServerError
      case G.UNIMPLEMENTED => A.NotImplemented
      case G.UNAVAILABLE => A.ServiceUnavailable
      case G.DEADLINE_EXCEEDED => A.GatewayTimeout
      case G.UNAUTHENTICATED | G.CANCELLED => A.InternalServerError
    

    Kind regards
    Ray

  3. Stephen

    Caveat to the above mapping, the last case overrides some of the prior cases. (UNAUTHENTICATED means there was a problem in json-api, since it checks for the presence of JWT itself. Likewise, json-api never cancels requests itself so such a grpc error means a problem within json-api.)