Перейти к основному содержимому

Errors

google.rpc.Status is used to describe API errors.

All errors will return 4xx/5xx HTTP response code with the following json body:

{
"code": 0,
"message": "string",
"details": []
}
  • code - gRPC error code. Error codes defined in google.rpc.Code
  • message - Human-readable error description. Client should not be depend on this field, as it can be changed in the future.
  • details - google.rpc.ErrDetails describes the message types that are used in the field.

Error handling

Use google.rpc.ErrorInfo to get more information about the error.

Code list

gRPC codegGRPC statusHTTP codeDescription
1CANCELLED499The operation was cancelled, typically by the caller.
2UNKNOWN500Unknown error
3INVALID_ARGUMENT400The client specified an invalid argument. Detailed info is provided in the details field.
4DEADLINE_EXCEEDED504The deadline expired before the operation could complete.
5NOT_FOUND404Some requested entity was not found.
6ALREADY_EXISTS409The entity that a client attempted to create already exists.
7PERMISSION_DENIED403The caller does not have permission to execute the specified operation.
8RESOURCE_EXHAUSTED429Some resource has been exhausted, perhaps a per-user quota, or perhaps the entire file system is out of space.
9FAILED_PRECONDITION400The operation was rejected because the system is not in a state required for the operation's execution. For example, the directory to be deleted is non-empty, an rmdir operation is applied to a non-directory, etc.
10ABORTED409The operation was aborted, typically due to a concurrency issue such as a sequencer check failure or transaction abort.
11OUT_OF_RANGE400The operation was attempted past the valid range. Unlike INVALID_ARGUMENT, this error indicates a problem that may be fixed if the system state changes.
12UNIMPLEMENTED501The operation is not implemented or is not supported/enabled in this service.
13INTERNAL500Internal errors. This means that some invariants expected by the underlying system have been broken. This error code is reserved for serious errors.
14UNAVAILABLE503The service is currently unavailable. This is most likely a transient condition, which can be corrected by retrying with a backoff.
15DATA_LOSS500Unrecoverable data loss or corruption.
16UNAUTHENTICATED401The request does not have valid authentication credentials for the operation.

Example:

const resp = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
})

if (resp.status === 200) {
// do something
return;
}

const errInfo = (
await resp.json())
.details
.find(d => d['@type'] === 'type.googleapis.com/google.rpc.ErrorInfo'
)
if (!errInfo) {
// something went wrong, internal server error
return;
}

const reason = errInfo.reason
switch (reason) {
case 'CREDENTIALS_INVALID':
// show error message
break;
default:
// something went wrong or unexpected error reason
// ...