Skip to content
This repository was 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
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
@@ -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'],
@@ -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`
1 change: 1 addition & 0 deletions lib/base-types.ts
Original file line number Diff line number Diff line change
@@ -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)[];
5 changes: 3 additions & 2 deletions lib/clients/http_client/http_client.ts
Original file line number Diff line number Diff line change
@@ -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}`,
@@ -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}`;
}