Is there a standard / best practice way to add a cause of an exception in javascript. In java you might do this:
Throwable t = new Exception("whatever"); t.addCause(previouslyCaughtException); throw t;
When the resulting exception is printed, it’ll give you a nice trace that includes causes. Is there any good way to do this in javascript or do I have to roll my own?
Advertisement
Answer
In prod, we use TraceError
Usage
import TraceError from 'trace-error'; global.TraceError = TraceError; // expose globally (optional) throw new TraceError('Could not set status', srcError, ...otherErrors);
Output