@lvce-editor/chat-tool-worker 9.24.0 → 9.26.0
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/dist/chatToolWorkerMain.js +46 -10
- package/package.json +1 -1
|
@@ -606,6 +606,9 @@ const restoreExistingError = (error, currentStack) => {
|
|
|
606
606
|
};
|
|
607
607
|
const restoreMethodNotFoundError = (error, currentStack) => {
|
|
608
608
|
const restoredError = new JsonRpcError(error.message);
|
|
609
|
+
Object.assign(restoredError, {
|
|
610
|
+
code: error.code
|
|
611
|
+
});
|
|
609
612
|
const parentStack = getParentStack(error);
|
|
610
613
|
setStack(restoredError, `${parentStack}${NewLine}${currentStack}`);
|
|
611
614
|
return restoredError;
|
|
@@ -625,9 +628,13 @@ const applyDataProperties = (restoredError, error) => {
|
|
|
625
628
|
// @ts-ignore
|
|
626
629
|
restoredError.codeFrame = error.data.codeFrame;
|
|
627
630
|
}
|
|
628
|
-
if (error.data.code) {
|
|
631
|
+
if (typeof error.data.code === 'string' || typeof error.data.code === 'number') {
|
|
629
632
|
// @ts-ignore
|
|
630
|
-
restoredError
|
|
633
|
+
Object.defineProperty(restoredError, 'code', {
|
|
634
|
+
configurable: true,
|
|
635
|
+
value: error.data.code,
|
|
636
|
+
writable: true
|
|
637
|
+
});
|
|
631
638
|
}
|
|
632
639
|
if (error.data.type) {
|
|
633
640
|
// @ts-ignore
|
|
@@ -648,7 +655,14 @@ const applyDirectProperties = (restoredError, error) => {
|
|
|
648
655
|
}
|
|
649
656
|
};
|
|
650
657
|
const restoreMessageError = (error, _currentStack) => {
|
|
651
|
-
const restoredError = constructError(error.message, error.type, error.name);
|
|
658
|
+
const restoredError = constructError(error.message, error.type || error.data?.type, error.name);
|
|
659
|
+
if (typeof error.code === 'string' || typeof error.code === 'number') {
|
|
660
|
+
Object.defineProperty(restoredError, 'code', {
|
|
661
|
+
configurable: true,
|
|
662
|
+
value: error.code,
|
|
663
|
+
writable: true
|
|
664
|
+
});
|
|
665
|
+
}
|
|
652
666
|
if (error.data) {
|
|
653
667
|
applyDataProperties(restoredError, error);
|
|
654
668
|
} else {
|
|
@@ -656,6 +670,23 @@ const restoreMessageError = (error, _currentStack) => {
|
|
|
656
670
|
}
|
|
657
671
|
return restoredError;
|
|
658
672
|
};
|
|
673
|
+
const getFallbackMessage = error => {
|
|
674
|
+
if (error && typeof error.message === 'string' && error.message) {
|
|
675
|
+
return error.message;
|
|
676
|
+
}
|
|
677
|
+
if (error && error.data) {
|
|
678
|
+
return getFallbackMessage(error.data);
|
|
679
|
+
}
|
|
680
|
+
const stringified = String(error);
|
|
681
|
+
if (stringified !== '[object Object]') {
|
|
682
|
+
return stringified;
|
|
683
|
+
}
|
|
684
|
+
try {
|
|
685
|
+
return JSON.stringify(error);
|
|
686
|
+
} catch {
|
|
687
|
+
return stringified;
|
|
688
|
+
}
|
|
689
|
+
};
|
|
659
690
|
const restoreJsonRpcError = error => {
|
|
660
691
|
const currentStack = getCurrentStack();
|
|
661
692
|
if (error && error instanceof Error) {
|
|
@@ -664,13 +695,13 @@ const restoreJsonRpcError = error => {
|
|
|
664
695
|
if (error && error.code && error.code === MethodNotFound) {
|
|
665
696
|
return restoreMethodNotFoundError(error, currentStack);
|
|
666
697
|
}
|
|
698
|
+
if (error && error.error) {
|
|
699
|
+
return restoreJsonRpcError(error.error);
|
|
700
|
+
}
|
|
667
701
|
if (error && error.message) {
|
|
668
702
|
return restoreMessageError(error);
|
|
669
703
|
}
|
|
670
|
-
|
|
671
|
-
return new Error(`JsonRpc Error: ${error}`);
|
|
672
|
-
}
|
|
673
|
-
return new Error(`JsonRpc Error: ${error}`);
|
|
704
|
+
return new Error(`JsonRpc Error: ${getFallbackMessage(error)}`);
|
|
674
705
|
};
|
|
675
706
|
const unwrapJsonRpcResult = responseMessage => {
|
|
676
707
|
if ('error' in responseMessage) {
|
|
@@ -727,9 +758,9 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
727
758
|
return {
|
|
728
759
|
code: Custom,
|
|
729
760
|
data: {
|
|
730
|
-
code: prettyError.code,
|
|
761
|
+
code: prettyError.code ?? error?.code,
|
|
731
762
|
codeFrame: prettyError.codeFrame,
|
|
732
|
-
name: prettyError.name,
|
|
763
|
+
name: prettyError.name ?? error?.name,
|
|
733
764
|
stack: getStack(prettyError),
|
|
734
765
|
type: getErrorType(prettyError)
|
|
735
766
|
},
|
|
@@ -764,7 +795,12 @@ const getErrorResponseSimple = (id, error) => {
|
|
|
764
795
|
return {
|
|
765
796
|
error: {
|
|
766
797
|
code: Custom,
|
|
767
|
-
data: error
|
|
798
|
+
data: error instanceof Error ? {
|
|
799
|
+
...error,
|
|
800
|
+
code: 'code' in error ? error.code : undefined,
|
|
801
|
+
stack: error.stack,
|
|
802
|
+
type: error.name
|
|
803
|
+
} : error,
|
|
768
804
|
// @ts-ignore
|
|
769
805
|
message: error.message
|
|
770
806
|
},
|