1. Developer guides

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 timeout when initializing the client.
  • Per-request timeout - set timeoutMs for an individual request. It overrides the global timeout without changing the timeout for other requests.

All timeout values are in milliseconds.

Before you begin

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.

import { ClientSDK } from "@sitecore-marketplace-sdk/client";
import { XMC } from "@sitecore-marketplace-sdk/xmc";

const client = await ClientSDK.init({
  target: window.parent,
  modules: [XMC],
  timeout: 5000,
});

Set timeout in the experimental client configuration:

import { experimental_createXMCClient } from "@sitecore-marketplace-sdk/xmc";

const xmc = await experimental_createXMCClient({
  getAccessToken,
  timeout: 5000,
});

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:

const { data, error } = await client.query("xmc.sites.listSites", {
  timeoutMs: 40000,
  params: {
    query: { sitecoreContextId: "<YOUR_CONTEXT_ID>" },
  },
});

if (error) {
  console.error("Error listing sites:", error);
} else {
  console.log("Sites:", data?.data);
}

For a mutation, set timeoutMs in the mutation options and handle errors using catch:

try {
  const response = await client.mutate("xmc.authoring.graphql", {
    timeoutMs: 40000,
    params: {
      query: { sitecoreContextId: "<YOUR_CONTEXT_ID>" },
      body: { query: "query { sites { name } }" },
    },
  });
  console.log("GraphQL response:", response);
} catch (error) {
  console.error("Error making GraphQL query:", error);
}

Set timeoutMs in the experimental method's options:

try {
  const { data, error } = await xmc.sites.listSites({
    query: { sitecoreContextId: "<YOUR_CONTEXT_ID>" },
    timeoutMs: 40000,
  });
  if (error) {
    console.error("Error listing sites:", error);
  } else {
    console.log("Sites:", data);
  }
} catch (error) {
  console.error("Error making Sites API request:", error);
}

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.

If you have suggestions for improving this article, let us know!