Skip to content
CCPEDIAby Unity Nodes
Discussions/App Development/Error code on JSON APIForum ↗

Error code on JSON API

App Development3 posts345 viewsLast activity Jul 2022
FR
FrankieOP
Jul 2022

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?

RA
Raymond_Roestenburg
Jul 2022

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

ST
Stephen
Jul 2022

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.)

← Back to Discussions