|
7 | 7 | LylaBrokenOnAfterResponseError,
|
8 | 8 | LylaBrokenOnResponseErrorError,
|
9 | 9 | LylaBrokenOnInitError,
|
10 |
| - LylaBrokenOnBeforeRequestError, |
11 |
| - isLylaError |
| 10 | + LylaBrokenOnBeforeRequestError |
12 | 11 | } from './error'
|
13 | 12 | import { mergeUrl, mergeHeaders, mergeOptions } from './utils'
|
14 | 13 | import type {
|
@@ -160,7 +159,7 @@ export function createLyla<C, M extends LylaAdapterMeta>(
|
160 | 159 | error: e,
|
161 | 160 | response: undefined,
|
162 | 161 | context: optionsWithContext.context,
|
163 |
| - requestOptions: optionsWithContext, |
| 162 | + requestOptions: optionsWithContext |
164 | 163 | },
|
165 | 164 | undefined
|
166 | 165 | )
|
@@ -734,36 +733,32 @@ export function createLyla<C, M extends LylaAdapterMeta>(
|
734 | 733 | try {
|
735 | 734 | response = await request(finalOptions)
|
736 | 735 | } catch (e) {
|
737 |
| - // expected error |
738 |
| - if (_isLylaError(e)) { |
739 |
| - let rejected: LylaRetryOnRejectedCommand<C, M> |
740 |
| - // onRejected throws an error |
741 |
| - try { |
742 |
| - rejected = await onRejected({ |
743 |
| - options: finalOptions as LylaRequestOptionsWithContext<C, M>, |
744 |
| - state, |
745 |
| - lyla, |
746 |
| - error: e |
747 |
| - }) |
748 |
| - } catch (e) { |
749 |
| - throw makeBrokenRetryError(e) |
750 |
| - } |
751 |
| - // expected error |
752 |
| - switch (rejected.action) { |
753 |
| - case 'reject': |
754 |
| - if (_isLylaError(rejected.value)) { |
755 |
| - throw rejected.value |
756 |
| - } else { |
757 |
| - throw makeRetryRejectedError(rejected.value) |
758 |
| - } |
759 |
| - case 'retry': |
760 |
| - retryOptionsResolver = rejected.value |
761 |
| - continue |
762 |
| - } |
763 |
| - } else { |
764 |
| - // If it goes here, this is a bug. |
| 736 | + let rejected: LylaRetryOnRejectedCommand<C, M> |
| 737 | + // onRejected throws an error |
| 738 | + try { |
| 739 | + rejected = await onRejected({ |
| 740 | + options: finalOptions as LylaRequestOptionsWithContext<C, M>, |
| 741 | + state, |
| 742 | + lyla, |
| 743 | + // The error can be a lyla error, or a custom error thrown by user |
| 744 | + // in lyla hooks. |
| 745 | + error: e |
| 746 | + }) |
| 747 | + } catch (e) { |
765 | 748 | throw makeBrokenRetryError(e)
|
766 | 749 | }
|
| 750 | + // expected error |
| 751 | + switch (rejected.action) { |
| 752 | + case 'reject': |
| 753 | + if (_isLylaError(rejected.value)) { |
| 754 | + throw rejected.value |
| 755 | + } else { |
| 756 | + throw makeRetryRejectedError(rejected.value) |
| 757 | + } |
| 758 | + case 'retry': |
| 759 | + retryOptionsResolver = rejected.value |
| 760 | + continue |
| 761 | + } |
767 | 762 | }
|
768 | 763 |
|
769 | 764 | let resolved: LylaRetryOnResolvedCommand<any, C, M>
|
|
0 commit comments