Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

[Feature] Global configuration to set default retries #759

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/reference/shopifyApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const shopify = shopifyApi({
apiVersion: ApiVersion.July22,
isEmbeddedApp: true,
isCustomStoreApp: false,
defaultRetries: 1,
userAgentPrefix: 'Custom prefix',
privateAppStorefrontAccessToken: 'PrivateAccessToken',
customShopDomains: ['*.my-custom-domain.io'],
Expand Down Expand Up @@ -87,6 +88,12 @@ Whether your app will run within the Shopify Admin. Learn more about embedded ap

Whether you are building a private app for a store.

### defaultRetries

`number` | Defaults to `1`

Set default retry attempts for Rest & GraphQL client.

### userAgentPrefix

`string` | Defaults to `undefined`
Expand Down
1 change: 1 addition & 0 deletions lib/base-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface ConfigParams<T extends ShopifyRestResources = any> {
apiVersion: ApiVersion;
isEmbeddedApp: boolean;
isCustomStoreApp?: boolean;
defaultRetries?: number;
userAgentPrefix?: string;
privateAppStorefrontAccessToken?: string;
customShopDomains?: (RegExp | string)[];
Expand Down
5 changes: 3 additions & 2 deletions lib/clients/http_client/http_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ export class HttpClient {
protected async request<T = unknown>(
params: RequestParams,
): Promise<RequestReturn<T>> {
const maxTries = params.tries ? params.tries : 1;
const config = this.httpClass().config;
const maxTries = params.tries ? params.tries : (config.defaultRetries ?? 1);
if (maxTries <= 0) {
throw new ShopifyErrors.HttpRequestError(
`Number of tries must be >= 0, got ${maxTries}`,
Expand All @@ -93,7 +94,7 @@ export class HttpClient {

let userAgent = `${LIBRARY_NAME} v${SHOPIFY_API_LIBRARY_VERSION} | ${abstractRuntimeString()}`;

if (this.httpClass().config.userAgentPrefix) {
if (config.userAgentPrefix) {
userAgent = `${this.httpClass().config.userAgentPrefix} | ${userAgent}`;
}

Expand Down