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 code | gGRPC status | HTTP code | Description |
---|---|---|---|
1 | CANCELLED | 499 | The operation was cancelled, typically by the caller. |
2 | UNKNOWN | 500 | Unknown error |
3 | INVALID_ARGUMENT | 400 | The client specified an invalid argument. Detailed info is provided in the details field. |
4 | DEADLINE_EXCEEDED | 504 | The deadline expired before the operation could complete. |
5 | NOT_FOUND | 404 | Some requested entity was not found. |
6 | ALREADY_EXISTS | 409 | The entity that a client attempted to create already exists. |
7 | PERMISSION_DENIED | 403 | The caller does not have permission to execute the specified operation. |
8 | RESOURCE_EXHAUSTED | 429 | Some resource has been exhausted, perhaps a per-user quota, or perhaps the entire file system is out of space. |
9 | FAILED_PRECONDITION | 400 | The 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. |
10 | ABORTED | 409 | The operation was aborted, typically due to a concurrency issue such as a sequencer check failure or transaction abort. |
11 | OUT_OF_RANGE | 400 | The operation was attempted past the valid range. Unlike INVALID_ARGUMENT, this error indicates a problem that may be fixed if the system state changes. |
12 | UNIMPLEMENTED | 501 | The operation is not implemented or is not supported/enabled in this service. |
13 | INTERNAL | 500 | Internal errors. This means that some invariants expected by the underlying system have been broken. This error code is reserved for serious errors. |
14 | UNAVAILABLE | 503 | The service is currently unavailable. This is most likely a transient condition, which can be corrected by retrying with a backoff. |
15 | DATA_LOSS | 500 | Unrecoverable data loss or corruption. |
16 | UNAUTHENTICATED | 401 | The 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
// ...