javascriptsentry

How can i change the name or message of a JavaScript Error object used in Sentry?


I have a JavaScript error object that I have caught in code. It has a name, message, stack etc that I want to log at the backend. I am using sentry for that. But before logging I want to change the name or the message of the error.

What will be the best way to do it? I tried creating a new error and adding the original error as cause, but that did not work with sentry. It just logs the error passed as the cause of the new error.

new Error('Additional error message', { cause: originalError });

I need the rest of the properties of the error to remain the same, just need to change the name or message.


Solution

  • I've made errors a bit readable with this:

    when you capture exception, add transactionName to scope.

    you can also enhance event in beforeSend method

    Sentry.captureException(error, (scope) => {
            ...
            scope.setTransactionName(`my custom title for error`);
            return scope;
        });
    

    Sentry error example: