commerce-sdk-isomorphic 5.1.0 → 5.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -138,6 +138,40 @@ try {
138
138
  }
139
139
  ```
140
140
 
141
+ #### `throwOnMaintenanceHeader`
142
+
143
+ When `true`, the SDK automatically detects maintenance mode by checking the `sfdc_maintenance` response header. If the header value is `'system'` or `'site'`, the SDK throws a `MaintenanceError` with status 503. This is useful for handling scheduled maintenance windows and displaying appropriate messaging to users. By default, this flag is `false` for backwards compatibility.
144
+
145
+ ```js
146
+ import {ShopperProducts, helpers} from 'commerce-sdk-isomorphic';
147
+ const {MaintenanceError} = helpers;
148
+
149
+ const config = {
150
+ throwOnMaintenanceHeader: true,
151
+ // rest of the config object...
152
+ };
153
+
154
+ const shopperProducts = new ShopperProducts(config);
155
+
156
+ // in an async function
157
+ try {
158
+ const product = await shopperProducts.getProduct({
159
+ parameters: {id: 'product-id'},
160
+ });
161
+ } catch (e) {
162
+ if (e instanceof MaintenanceError) {
163
+ console.log(`Service in maintenance: ${e.maintenanceType}`); // 'system' or 'site'
164
+ console.log(`Status: ${e.status}`); // 503
165
+ // Display maintenance page to user
166
+ } else {
167
+ // Handle other errors
168
+ console.error('API error:', e);
169
+ }
170
+ }
171
+ ```
172
+
173
+ **Note:** The maintenance check occurs before other error handling and applies even when using `rawResponse: true`.
174
+
141
175
  #### Additional Config Settings
142
176
 
143
177
  * `headers`: Headers to include with API requests.