If an error occurs while an RPC method executes, Pub/Sub API throws a gRPC
StatusRuntimeException
that contains a status code. The exception causes the long-lived connection for the
PublishStream
,
Subscribe
, and
ManagedSubscribe (beta)
RPC methods to stop. Retry the RPC methods to create a new long-lived connection.
The gRPC status codes can be found
here
. In your code, catch the exceptions after performing an RPC method call, and handle the error.
The status fields differ depending on the programming language. For example, in Java, the fields are
code
and
description
and in Python they're
code
and
details
. To get status fields in Java, after catching the exception, you can call the
getStatus()
Java method on the exception to get the
Status
object. Next, call
getCode()
and
getDescription()
on the status. To get status fields in Python, after catching the exception, you can call the
code
and
details
methods on the exception.
The Pub/Sub API adds a custom error code in the Trailers section of the exception. You can retrieve the custom error code by calling
getTrailers()
on the exception. The error code provides information about the cause of the failure.
Also, the exception contains an RPC ID that the Pub/Sub API appends to the error message after the “
rpcId:
" prefix. The RPC ID is also included in the Trailers section of the exception. The RPC ID identifies the method execution that caused the exception and can aid Salesforce Customer Support in troubleshooting the error. If you can’t resolve the error by looking up the error code and the documentation, contact Salesforce Customer Support for help and provide the
rpcId
value.
Exception Example
In the example gRPC exception below, the status returned is
INVALID_ARGUMENT
, and the custom error code from the Pub/Sub API is:
[Trailer] = error-code [Value] = sfdc.platform.eventbus.grpc.subscription.fetch.replayid.corrupted
=== GRPC Exception ===
io.grpc.StatusRuntimeException: INVALID_ARGUMENT: The Replay ID validation failed. Ensure that the Replay ID is valid. rpcId: 2f6b4cee-3525-49d1-8fdb-0bd3d662062f
=== Trailers ===
[Trailer] = content-type [Value] = application/grpc
[Trailer] = rpc-id [Value] = 2f6b4cee-3525-49d1-8fdb-0bd3d662062f
[Trailer] = error-code [Value] = sfdc.platform.eventbus.grpc.subscription.fetch.replayid.corrupted
[Trailer] = type [Value] = Subscribe
The Salesforce org isn’t licensed to access the Pub/Sub API. Contact Salesforce to enable the API. If you get this error even though your org is enabled for Pub/Sub API, retry the RPC method call. The cause of this error can be an intermittent issue with the service when it fails to verify the org’s access to Pub/Sub API.
No publish request was received during the timeout period of 1,800 seconds (30 minutes). The publish stream timed out.
CANCELLED
Subscription Errors
These error codes apply to both subscriptions and managed subscriptions. These errors cause the long-lived connection for the
Subscribe
or
ManagedSubscribe
RPC method to stop. Retry the RPC method call to create a new long-lived connection.
The Replay ID validation failed. The
replay_preset
field in FetchRequest is set to
ReplayPreset.CUSTOM
, but no Replay ID value is set in
replay_id
. Provide a Replay ID in the
replay_id
field to subscribe after the custom Replay ID.
The Replay ID validation failed. Ensure that the
replay_id
field value in FetchRequest is valid and refers to an event that is within the retention window.
Due to an internal error, the server received an event that’s older than the one received earlier. Its Replay ID value is lower than that of the last received event.
The fetch request is missing an auth refresh. Include an auth refresh when sending a fetch request with zero events requested. The auth refresh is for Salesforce internal use only.
Can’t subscribe to the specified topic. Check that you have the required permissions.
PERMISSION_DENIED
Managed Subscription Errors
These error codes apply to managed subscriptions only. These errors cause the long-lived connection for the
ManagedSubscribe
RPC method to stop. Retry the RPC method call to create a new long-lived connection.
An active managed subscription with the same ID already exists. If a previous subscription with the same ID was stopped, there can be a delay before it expires. Try subscribing again later.
The managed subscription configuration isn't found. Ensure the developer name is correct and that the managed subscription configuration exists. If the configuration was recently created, try again.
The managed fetch request is missing a CommitReplayRequest or an auth refresh. Include a CommitReplayRequest or an auth refresh when sending a request with zero events requested. The auth refresh is for Salesforce internal use only.
The managed subscription configuration isn't found. Ensure the subscription ID is correct and that the managed subscription configuration exists. If the configuration was recently created, try again.
NOT_FOUND
Errors in CommitResponse
These errors don't cause the long-lived connection for the
ManagedSubscribe
RPC method to stop. These errors are part of the
CommitResponse
that is returned after sending a
CommitReplayRequest
to commit a Replay ID.
Error Code
Error Description
COMMIT
No Replay ID was provided to commit. Specify a Replay ID in CommitReplayRequest.
COMMIT
The Replay ID provided in the commit request is invalid. Ensure the Replay ID in CommitReplayRequest is valid. If the Replay ID is old, it can be outside the event retention window and is no longer valid.
COMMIT
The commit request was received before the subscription delivered any events. Wait for event delivery before attempting to commit a Replay ID.
COMMIT
The Replay ID commit request failed. For information about how to handle the Replay ID commit failure, check the documentation.
COMMIT
The Replay ID in this commit request is older than the currently committed Replay ID.