lissa 1.0.2 → 1.0.4

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
@@ -478,8 +478,9 @@ Decide if the occurred error should trigger a retry.
478
478
  The given errorType helps preselecting error types. Return false to not
479
479
  trigger a retry. Return nothing if the given errorType is correct. Return
480
480
  a string to redefine the errorType or use a custom one. The number of
481
- maximum retries can be configured as `on${errorType}`. Return "CustomError"
482
- and define the retries as { onCustomError: 3 }
481
+ maximum retries can be configured as `on${errorType}` or `@${errorType}`.
482
+ Return "CustomError" and define the retries as { onCustomError: 3 } or
483
+ as { '@CustomError': 3 }.
483
484
 
484
485
  ```js
485
486
  Lissa.retry({
package/lib/index.d.ts CHANGED
@@ -317,14 +317,14 @@ export interface Lissa extends MakeRequest {
317
317
  *
318
318
  * Modify the given options as argument or return a new options object.
319
319
  */
320
- beforeRequest(hook: (options: LissaOptions) => void | LissaOptions): Lissa;
320
+ beforeRequest(hook: (options: LissaOptions) => void | LissaOptions | Promise<void | LissaOptions>): Lissa;
321
321
 
322
322
  /**
323
323
  * Add a beforeFetch hook into the request cycle.
324
324
  *
325
325
  * Modify the actual fetch arguments or return new arguments.
326
326
  */
327
- beforeFetch(hook: (request: FetchArguments) => void | FetchArguments): Lissa;
327
+ beforeFetch(hook: (request: FetchArguments) => void | FetchArguments | Promise<void | FetchArguments>): Lissa;
328
328
 
329
329
  /**
330
330
  * Add an onResponse hook into the request cycle.
@@ -333,7 +333,7 @@ export interface Lissa extends MakeRequest {
333
333
  * stop looping over existing hooks and instantly returns this value (if it
334
334
  * is an instance of Error it will get thrown).
335
335
  */
336
- onResponse(hook: (result: LissaResult) => void | Exclude<any, undefined>): Lissa;
336
+ onResponse(hook: (result: LissaResult) => void | Exclude<any, undefined> | Promise<void | Exclude<any, undefined>>): Lissa;
337
337
 
338
338
  /**
339
339
  * Add an onError hook into the request cycle.
@@ -342,7 +342,7 @@ export interface Lissa extends MakeRequest {
342
342
  * over existing hooks and instantly returns this value (if it is an instance
343
343
  * of Error it will get thrown).
344
344
  */
345
- onError(hook: (error: ResponseError | ConnectionError | GeneralErrorResponse) => void | Exclude<any, undefined>): Lissa;
345
+ onError(hook: (error: ResponseError | ConnectionError | GeneralErrorResponse) => void | Exclude<any, undefined> | Promise<void | Exclude<any, undefined>>): Lissa;
346
346
 
347
347
  /**
348
348
  * Copy the current instance with all its options and hooks.
@@ -421,14 +421,14 @@ export declare const retry: (options?: RetryOptions) => Plugin;
421
421
 
422
422
  export type CustomRetryError = {
423
423
  /** custom retry type have to be returned by shouldRetry hook */
424
- [K in `on${string}`]: number;
424
+ [K in `@${string}`]: number;
425
425
  };
426
426
 
427
427
  export type RetryOptions = CustomRetryError & {
428
- onConnectionError?: number;
429
- onGatewayError?: number;
430
- on429?: number;
431
- onServerError?: number;
428
+ '@ConnectionError'?: number;
429
+ '@GatewayError'?: number;
430
+ '@429'?: number;
431
+ '@ServerError'?: number;
432
432
 
433
433
  /**
434
434
  * Decide if the occurred error should trigger a retry.
@@ -436,8 +436,9 @@ export type RetryOptions = CustomRetryError & {
436
436
  * The given errorType helps preselecting error types. Return false to not
437
437
  * trigger a retry. Return nothing if the given errorType is correct. Return
438
438
  * a string to redefine the errorType or use a custom one. The number of
439
- * maximum retries can be configured as `on${errorType}`. Return "CustomError"
440
- * and define the retries as { onCustomError: 3 }
439
+ * maximum retries can be configured as `on${errorType}` or `@${errorType}`.
440
+ * Return "CustomError" and define the retries as { onCustomError: 3 } or
441
+ * as { '@CustomError': 3 }.
441
442
  */
442
443
  shouldRetry?: (
443
444
  errorType: void | 'ConnectionError' | 'GatewayError' | '429' | 'ServerError',
@@ -42,7 +42,7 @@ export default (options = {}) => (lissa) => {
42
42
  }
43
43
 
44
44
  // Return nothing to hand over the error to the next onError hook
45
- if (retry.attempt > (options[`on${errorType}`] || 0)) return;
45
+ if (retry.attempt > (options[`@${errorType}`] ?? options[`on${errorType}`] ?? 0)) return;
46
46
 
47
47
  await new Promise(resolve => setTimeout(resolve, retry.delay));
48
48
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lissa",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "A lightweight, extensible HTTP client for modern JavaScript applications with fluent api syntax, hooks, plugins and more.",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",