In this case, you need to know two points. Both points are independent of each other and must be fixed to solve your problem.
First
The error you encounter is a special type of error called Script Error
A “Script error” is what browsers send to an onerror when an error occurs from a JavaScript file filed from a different source (different domain, port or protocol). It hurts because even though an error occurs, you don’t know what the error is, it didn’t come from any code.
This is not a JavaScript error.
Browsers intentionally hide errors from script files from various sources for reasons of safety. To avoid unintentional leakage of script-sensitive information to the onerror return signal, which it does not control. For this reason, browsers only give window.onerror understanding of errors originating from the same domain. All we know is that the error happened - nothing more!
To fix this problem:
To fix and get a normal error object, flag this blog post
Second
When you try to compress any Error object, the result will not satisfy at all, because you will lose almost all the data.
The reason of that
JSON.stringify deals only with enumerated properties, but the Error object stores contextual data in unnamed properties.
To fix this problem
There are many solutions, but it can be straightforward.
JSON.stringify(err, ["message", "arguments", "type", "name"])
This selects the properties you need and generates a string for you.