@salesforce/core 8.2.2 → 8.2.3
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/lib/sfError.js +20 -9
- package/package.json +1 -1
package/lib/sfError.js
CHANGED
|
@@ -99,15 +99,10 @@ class SfError extends Error {
|
|
|
99
99
|
if (err instanceof SfError) {
|
|
100
100
|
return err;
|
|
101
101
|
}
|
|
102
|
-
const sfError = err
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
name: err.name,
|
|
107
|
-
cause: err,
|
|
108
|
-
})
|
|
109
|
-
: // ok, something was throws that wasn't error or string. Convert it to an Error that preserves the information as the cause and wrap that.
|
|
110
|
-
SfError.wrap(new Error(`SfError.wrap received type ${typeof err} but expects type Error or string`, { cause: err }));
|
|
102
|
+
const sfError = fromBasicError(err) ??
|
|
103
|
+
fromErrorLikeObject(err) ??
|
|
104
|
+
// something was thrown that wasn't error, error-like object or string. Convert it to an Error that preserves the information as the cause and wrap that.
|
|
105
|
+
SfError.wrap(new Error(`SfError.wrap received type ${typeof err} but expects type Error or string`, { cause: err }));
|
|
111
106
|
// If the original error has a code, use that instead of name.
|
|
112
107
|
if ((0, ts_types_1.hasString)(err, 'code')) {
|
|
113
108
|
sfError.code = err.code;
|
|
@@ -147,4 +142,20 @@ class SfError extends Error {
|
|
|
147
142
|
}
|
|
148
143
|
}
|
|
149
144
|
exports.SfError = SfError;
|
|
145
|
+
const fromBasicError = (err) => err instanceof Error ? SfError.create({ message: err.message, name: err.name, cause: err }) : undefined;
|
|
146
|
+
/* an object that is the result of spreading an Error or SfError */
|
|
147
|
+
const fromErrorLikeObject = (err) => {
|
|
148
|
+
if (!err || typeof err !== 'object') {
|
|
149
|
+
return undefined;
|
|
150
|
+
}
|
|
151
|
+
if (!('message' in err)) {
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
154
|
+
try {
|
|
155
|
+
return SfError.create(err);
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
return undefined;
|
|
159
|
+
}
|
|
160
|
+
};
|
|
150
161
|
//# sourceMappingURL=sfError.js.map
|