@lvce-editor/json-rpc 6.0.0 → 6.1.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.
Files changed (2) hide show
  1. package/dist/index.js +17 -9
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -120,6 +120,19 @@ const constructError = (message, type, name) => {
120
120
  return new ErrorConstructor(message);
121
121
  };
122
122
 
123
+ const joinLines = lines => {
124
+ return lines.join(NewLine);
125
+ };
126
+
127
+ const splitLines = lines => {
128
+ return lines.split(NewLine);
129
+ };
130
+
131
+ const getCurrentStack = () => {
132
+ const currentStack = joinLines(splitLines(new Error().stack || '').slice(2));
133
+ return currentStack;
134
+ };
135
+
123
136
  const getNewLineIndex = (string, startIndex = undefined) => {
124
137
  return string.indexOf(NewLine, startIndex);
125
138
  };
@@ -132,22 +145,17 @@ const getParentStack = error => {
132
145
  return parentStack;
133
146
  };
134
147
 
135
- const joinLines = lines => {
136
- return lines.join(NewLine);
137
- };
138
-
139
148
  const MethodNotFound = -32601;
140
149
  const Custom = -32001;
141
150
 
142
- const splitLines = lines => {
143
- return lines.split(NewLine);
144
- };
145
-
146
151
  const restoreJsonRpcError = error => {
152
+ const currentStack = getCurrentStack();
147
153
  if (error && error instanceof Error) {
154
+ if (typeof error.stack === 'string') {
155
+ error.stack = error.stack + NewLine + currentStack;
156
+ }
148
157
  return error;
149
158
  }
150
- const currentStack = joinLines(splitLines(new Error().stack || '').slice(1));
151
159
  if (error && error.code && error.code === MethodNotFound) {
152
160
  const restoredError = new JsonRpcError(error.message);
153
161
  const parentStack = getParentStack(error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/json-rpc",
3
- "version": "6.0.0",
3
+ "version": "6.1.0",
4
4
  "description": "JsonRpc implementation",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",