refactor(core): Display stack trace in error reporter (no-changelog) (#10225)

This commit is contained in:
Iván Ovejero 2024-07-29 17:27:02 +02:00 committed by GitHub
parent 1a7713ef26
commit de50ef7590
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -5,13 +5,17 @@ interface ErrorReporter {
report: (error: Error | string, options?: ReportingOptions) => void;
}
const { NODE_ENV } = process.env;
const inDevelopment = !NODE_ENV || NODE_ENV === 'development';
const instance: ErrorReporter = {
report: (error) => {
if (error instanceof Error) {
let e = error;
do {
const meta = e instanceof ApplicationError ? e.extra : undefined;
Logger.error(`${e.constructor.name}: ${e.message}`, meta);
if (inDevelopment) console.log(e, meta);
else Logger.error(`${e.constructor.name}: ${e.message}`, meta);
e = e.cause as Error;
} while (e);
}