You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+48Lines changed: 48 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -330,6 +330,54 @@ interface Evaluation {
330
330
}
331
331
```
332
332
333
+
## Authentication Request Timeout
334
+
335
+
The `authRequestReadTimeout` option allows you to specify a timeout in milliseconds for the authentication request. If the request takes longer than this timeout, it will be aborted. This is useful for preventing hanging requests due to network issues or slow responses.
336
+
337
+
If the request is aborted due to this timeout the SDK will fail to initialize and an `ERROR_AUTH` and `ERROR` event will be emitted.
338
+
339
+
**This only applies to the authentiaction request. If you wish to set a read timeout on the remaining requests made by the SDK, you may register [API Middleware](#api-middleware)
340
+
341
+
```typescript
342
+
const options = {
343
+
authRequestReadTimeout: 30000, // Timeout in milliseconds (default: 30000)
344
+
};
345
+
346
+
const client =initialize(
347
+
'YOUR_API_KEY',
348
+
{
349
+
identifier: 'Harness1',
350
+
attributes: {
351
+
lastUpdated: Date(),
352
+
host: location.href,
353
+
},
354
+
},
355
+
options
356
+
);
357
+
```
358
+
359
+
## API Middleware
360
+
The `registerAPIRequestMiddleware` function allows you to register a middleware function to manipulate the payload (URL, body and headers) of API requests after the AUTH call has successfully completed
361
+
362
+
```typescript
363
+
function abortControllerMiddleware([url, options]) {
364
+
if (window.AbortController) {
365
+
const abortController =newAbortController();
366
+
options.signal=abortController.signal;
367
+
368
+
// Set a timeout to automatically abort the request after 30 seconds
369
+
setTimeout(() =>abortController.abort(), 30000);
370
+
}
371
+
372
+
return [url, options]; // Return the modified or original arguments
This example middleware will automatically attach an AbortController to each request, which will abort the request if it takes longer than the specified timeout. You can also customize the middleware to perform other actions, such as logging or modifying headers.
379
+
380
+
333
381
## Logging
334
382
By default, the Javascript Client SDK will log errors and debug messages using the `console` object. In some cases, it
335
383
can be useful to instead log to a service or silently fail without logging errors.
Copy file name to clipboardExpand all lines: src/types.ts
+6Lines changed: 6 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -133,6 +133,12 @@ export interface Options {
133
133
* Whether to enable debug logging.
134
134
* @default false
135
135
*/
136
+
authRequestReadTimeout?: number
137
+
/**
138
+
* The timeout in milliseconds for the authentication request to read the response.
139
+
* If the request takes longer than this timeout, it will be aborted and the SDK will fail to initialize, and `ERROR_AUTH` and `ERROR` events will be emitted.
0 commit comments