Skip to content
Documentation
Status

Status

The gRPCity library provides a convenient way to obtain status. In general, you won’t need to use it often, but I’ll provide a brief overview here.

Get Status

Obtaining the Status object by grpcity:

import { Status } from 'grpcity'
 
console.log(Status.OK)

Obtaining the status returned by the server is straightforward for the client, as shown below:

const client = clients.get('path.to.service')
const { status } = await client.rpcMethod()
console.log(status)
 
 
// The printed result after execution
{
    code: 0,
    details: 'OK',
    metadata: Metadata { internalRepr: Map(0) {}, options: {} }
}

Status Codes

The default status codes and their descriptions are as follows:

CodeNumberDescription
OK0No error; indicates a successful return.
CANCELLED1The operation was cancelled, typically by the caller.
UNKNOWN2Unknown error. For example, when a status value received from a different address space is unknown within this address space, this error may be returned. It may also be used to translate errors that are not returned with sufficient detail by APIs.
INVALID_ARGUMENT3The client specified an invalid argument. Note that this differs from “FAILED_PRECONDITION.” “INVALID_ARGUMENT” indicates arguments that are problematic regardless of the system state (e.g., a file format error).
DEADLINE_EXCEEDED4The deadline expired before the operation could complete. For operations that change the system state, this error may be returned even if the operation has completed successfully. For example, a successful response from a server that was delayed long enough for the client to disconnect may lead to this error.
NOT_FOUND5Some requested entity (e.g., file or directory) was not found. Server developers should consider returning “NOT_FOUND” if an RPC should be rejected for an entire class of users, such as gradual feature rollout or undocumented whitelist. If a request is rejected for some users in a user class based on, for example, user-based access control, “PERMISSION_DENIED” must be used.
ALREADY_EXISTS6The client attempted to create an entity (e.g., a file or directory) that already exists.
PERMISSION_DENIED7The caller does not have permission to execute the specified operation. “PERMISSION_DENIED” must not be used for errors caused by exhausting some resource (use “RESOURCE_EXHAUSTED” instead). “PERMISSION_DENIED” must not be used if the caller cannot be identified.
RESOURCE_EXHAUSTED8Some resource has been exhausted, such as a per-user quota, or the entire file system is out of space.
FAILED_PRECONDITION9The operation was rejected because the system is not in a state required for the operation. For example, an attempt to delete a directory that is non-empty, even though it is a directory, would result in “FAILED_PRECONDITION.” Service implementers can use the following guidelines to choose between “FAILED_PRECONDITION,” “ABORTED,” and “UNAVAILABLE”: (a) If the client can retry the failed call, use “UNAVAILABLE.” (b) If the client should not retry at a higher level, use “ABORTED” (for example, when a client specifies a test and the set fails). (c) If the client should not retry until the system state is fixed, use “FAILED_PRECONDITION.” For example, if a directory is not empty, “rmdir” should fail because the client should not retry unless it first removes the files from the directory.
ABORTED10The operation was aborted, typically due to a concurrency issue, such as a sequencer check failure or a transaction abort. Service implementers can use the following guidelines to choose between “FAILED_PRECONDITION,” “ABORTED,” and “UNAVAILABLE”: (a) If the client can retry the failed call, use “UNAVAILABLE.” (b) If the client should retry at a higher level, use “ABORTED” (for example, when a client specifies a test and the set fails). (c) If the client should not retry until the system state is fixed, use “FAILED_PRECONDITION.” For example, “rmdir” might fail if it is called on a non-empty directory, but the client should not retry until it removes the files from the directory.
OUT_OF_RANGE11The operation was attempted past the valid range. For example, reading or writing past the end of a file. Unlike “INVALID_ARGUMENT,” this error indicates a problem that may be fixed if the system state changes. For example, if a 32-bit file system is asked to read at a certain offset that is not in the range [0,2^32-1], it will generate “INVALID_ARGUMENT,” but if asked to read from an offset that is past the current file size, it will generate “OUT_OF_RANGE.” “RESUMED: FAILED_PRECONDITION” and “OUT_OF_RANGE” have a small overlap. We recommend using “OUT_OF_RANGE” (the more specific error) when it is applicable so that callers who iterate through space can easily locate “OUT_OF_RANGE” errors.
UNIMPLEMENTED12The operation is not implemented or not supported/enabled in this service.
INTERNAL13Internal error. This means that some invariant expected by the underlying system has been broken. This error code is reserved for serious errors.
UNAVAILABLE14The service is currently unavailable. This is most likely a transient condition that can be corrected by retrying with an exponential backoff. Note that it is not always safe to retry non-idempotent operations.
DATA_LOSS15Unrecoverable data loss or corruption.
UNAUTHENTICATED16The request does not have valid authentication credentials.

Status Cases

In addition to “OK,” you should also be aware of the possible reasons for other Code values, as shown in the following table:

CaseCodeClient or Server
The client’s application cancelled the requestCANCELLEDBoth
The deadline expired before the server returned a statusDEADLINE_EXCEEDEDBoth
The method was not found on the serverUNIMPLEMENTEDServer
The server is shutting downUNAVAILABLEServer
The server application throws an exception (or performs an action other than returning a status code, terminating the RPC)UNKNOWNServer
The deadline expired before a response was received. This can happen when the client is unable to send the request to the server or the server is slow to respond.DEADLINE_EXCEEDEDBoth
Some data was sent before the connection was terminated (e.g. writing request metadata to the TCP connection)UNAVAILABLEClient
The server was unable to decompress data, although the compression algorithm was supported (client to server)INTERNALServer
The server was unable to decompress data, although the compression algorithm was supported (server to client)INTERNALClient
The compression mechanism used by the client is not supported on the serverUNIMPLEMENTEDServer
The server’s temporary resources are exhausted (e.g. reaching the rate-limiting resource limit)RESOURCE_EXHAUSTEDServer
The client does not have enough memory to store the server’s responseRESOURCE_EXHAUSTEDClient
A traffic control protocol violation occurredINTERNALBoth
An error occurred while parsing the returned statusUNKNOWNClient
Invalid authentication metadata (credentials couldn’t be obtained from the metadata, incompatible credentials set on the channel and call, invalid host set in :authority metadata, etc.)UNAUTHENTICATEDBoth
Request cardinality violation (method requires exactly one request, but the client sent a different number of requests)UNIMPLEMENTEDServer
Response cardinality violation (method requires exactly one response, but the server sent a different number of responses)UNIMPLEMENTEDClient
An error occurred while parsing the response protocolINTERNALClient
An error occurred while parsing the request protocolINTERNALServer
Messages sent or received were larger than the configured limitRESOURCE_EXHAUSTEDBoth
Keepalive monitor timeoutUNAVAILABLEBoth