Skip to content

Commit 5b03656

Browse files
committed
fix: skip adding a toJSON method to errors that already have one (#61)
1 parent 394b2d6 commit 5b03656

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/LogMessage.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ class LogMessage {
229229
* @returns {Error} The original error stubbed with a toJSON() method.
230230
*/
231231
static stubError(err) {
232+
if(typeof err.toJSON === 'function') return err;
233+
232234
err.toJSON = function () {
233235
const keys = [
234236
'name',
@@ -239,9 +241,9 @@ class LogMessage {
239241
return keys.reduce((obj, key) => {
240242
if(key in err) {
241243
const val = err[key];
242-
if(typeof val !== 'function') {
243-
obj[key] = val;
244-
}
244+
245+
if(typeof val === 'function') return obj;
246+
obj[key] = val;
245247
}
246248

247249
return obj;

0 commit comments

Comments
 (0)