Is it not possible to stringify an Error using JSON.stringify?

后端 未结 11 2049
心在旅途
心在旅途 2020-11-22 07:54

Reproducing the problem

I\'m running into an issue when trying to pass error messages around using web sockets. I can replicate the issue I am facing using J

11条回答
  •  囚心锁ツ
    2020-11-22 08:27

    You can also just redefine those non-enumerable properties to be enumerable.

    Object.defineProperty(Error.prototype, 'message', {
        configurable: true,
        enumerable: true
    });
    

    and maybe stack property too.

提交回复
热议问题