@lvce-editor/json-rpc 8.7.0 → 8.8.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/index.js +23 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -181,6 +181,9 @@ const restoreExistingError = (error, currentStack) => {
|
|
|
181
181
|
};
|
|
182
182
|
const restoreMethodNotFoundError = (error, currentStack) => {
|
|
183
183
|
const restoredError = new JsonRpcError(error.message);
|
|
184
|
+
Object.assign(restoredError, {
|
|
185
|
+
code: error.code
|
|
186
|
+
});
|
|
184
187
|
const parentStack = getParentStack(error);
|
|
185
188
|
setStack(restoredError, `${parentStack}${NewLine}${currentStack}`);
|
|
186
189
|
return restoredError;
|
|
@@ -200,9 +203,13 @@ const applyDataProperties = (restoredError, error) => {
|
|
|
200
203
|
// @ts-ignore
|
|
201
204
|
restoredError.codeFrame = error.data.codeFrame;
|
|
202
205
|
}
|
|
203
|
-
if (error.data.code) {
|
|
206
|
+
if (typeof error.data.code === 'string' || typeof error.data.code === 'number') {
|
|
204
207
|
// @ts-ignore
|
|
205
|
-
restoredError
|
|
208
|
+
Object.defineProperty(restoredError, 'code', {
|
|
209
|
+
configurable: true,
|
|
210
|
+
value: error.data.code,
|
|
211
|
+
writable: true
|
|
212
|
+
});
|
|
206
213
|
}
|
|
207
214
|
if (error.data.type) {
|
|
208
215
|
// @ts-ignore
|
|
@@ -224,6 +231,13 @@ const applyDirectProperties = (restoredError, error) => {
|
|
|
224
231
|
};
|
|
225
232
|
const restoreMessageError = (error, _currentStack) => {
|
|
226
233
|
const restoredError = constructError(error.message, error.type, error.name);
|
|
234
|
+
if (typeof error.code === 'string' || typeof error.code === 'number') {
|
|
235
|
+
Object.defineProperty(restoredError, 'code', {
|
|
236
|
+
configurable: true,
|
|
237
|
+
value: error.code,
|
|
238
|
+
writable: true
|
|
239
|
+
});
|
|
240
|
+
}
|
|
227
241
|
if (error.data) {
|
|
228
242
|
applyDataProperties(restoredError, error);
|
|
229
243
|
} else {
|
|
@@ -308,7 +322,7 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
308
322
|
return {
|
|
309
323
|
code: Custom,
|
|
310
324
|
data: {
|
|
311
|
-
code: prettyError.code,
|
|
325
|
+
code: prettyError.code ?? error?.code,
|
|
312
326
|
codeFrame: prettyError.codeFrame,
|
|
313
327
|
name: prettyError.name,
|
|
314
328
|
stack: getStack(prettyError),
|
|
@@ -350,7 +364,12 @@ const getErrorResponseSimple = (id, error) => {
|
|
|
350
364
|
return {
|
|
351
365
|
error: {
|
|
352
366
|
code: Custom,
|
|
353
|
-
data: error
|
|
367
|
+
data: error instanceof Error ? {
|
|
368
|
+
...error,
|
|
369
|
+
code: 'code' in error ? error.code : undefined,
|
|
370
|
+
stack: error.stack,
|
|
371
|
+
type: error.name
|
|
372
|
+
} : error,
|
|
354
373
|
// @ts-ignore
|
|
355
374
|
message: error.message
|
|
356
375
|
},
|