Configure request timeouts
You can configure how long your Marketplace app waits for an SDK request to complete. This is useful when an operation, such as generating a brand review, takes longer than the default timeout.
The SDK supports two timeout levels:
- Global timeout - set
timeoutwhen initializing the client. - Per-request timeout - set
timeoutMsfor an individual request. It overrides the global timeout without changing the timeout for other requests.
All timeout values are in milliseconds.
- Complete an SDK quick start.
- For the client-side examples, initialize the
xmcpackage. - For server-side requests, use a full-stack app with custom authorization. The server-side initialization example uses your app's
getAccessTokenfunction to return a bearer token.
Configure the global timeout
Add timeout to your client initialization code. All requests use this value unless you set a per-request timeout.
The following examples set the global timeout to 5,000 milliseconds (5 seconds):
The client package uses a default timeout of 30,000 milliseconds (30 seconds) if you don't set timeout.
Set timeout in the experimental client configuration:
Configure a per-request timeout
Add timeoutMs to the request options, not to params. The following examples use a timeout of 40,000 milliseconds (40 seconds) for that request only.
Replace <YOUR_CONTEXT_ID> with the Context ID of your SitecoreAI environment, which you can retrieve from the application context.
For a query, set timeoutMs in the query options and check the returned error:
For a mutation, set timeoutMs in the mutation options and handle errors using catch:
Set timeoutMs in the experimental method's options:
Handle timeout errors
For client-side queries, check the returned error or use the onError callback. Mutations reject when a request times out, so use catch to handle the error.
A timeout doesn't confirm that the operation was canceled. Check whether a mutation succeeded before retrying it.
For more information, see Troubleshooting the Marketplace SDK.