mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-09-21 15:56:10 +08:00
[iso-core] fix error toJSON in node environments
Summary: Node's native `Error` object does NOT implement toJSON. We attempt to call toJSON when reporting errors. This wasn't noticed until now because bunyan's pretty logger (which only run in dev mode) started JSONifying errors Test Plan: Try and API auth with a bad username with local setup. See that it throws toJSON error. After patch, error properly serializes Reviewers: spang, halla, jerm, juan Reviewed By: juan Differential Revision: https://phab.nylas.com/D3975
This commit is contained in:
parent
c149e9171d
commit
5577d1b4d3
|
@ -1,7 +1,11 @@
|
|||
|
||||
class NylasError extends Error {
|
||||
toJSON() {
|
||||
const json = super.toJSON() || {}
|
||||
let json = {}
|
||||
if (super.toJSON) {
|
||||
// Chromium `Error`s have a `toJSON`, but Node `Error`s do NOT!
|
||||
json = super.toJSON()
|
||||
}
|
||||
Object.getOwnPropertyNames(this).forEach((key) => {
|
||||
json[key] = this[key];
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue