Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

221
Visualizações
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.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

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:

about 4 years ago · Juan Pablo Isaza Relatório

0

A super helpful thing you can do to accomplish this is actually create your own custom error types. This can be done by simply using a class that extends the Error constructor, like so:

class MyError extends Error {
  constructor(message) {
    super();
    this.name = "MyError";
    this.message = message;
  }
}
try {
  throw new MyError('this is my error')
} catch (err) {
  console.log(err instanceof Error);
  console.log(err.message);
  console.log(err.name);
  console.log(err.stack);
}

class ExtendedError extends Error {
  constructor(message, { cause }) {
    super();
    this.name = "ExtendedError";
    this.message = message;
    // set the cause to maintain linkage to the original error
    this.cause = cause;
  }
}
try {
  throw new Error('Something bad happened!');
} catch (err) {
  let extendedError = new ExtendedError('Additional details', { cause: err });
  console.log(extendedError instanceof Error);
  console.log(extendedError.message);
  console.log(extendedError.name);
  console.log(extendedError.cause.stack);
  console.log(extendedError.stack);
}

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda