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

104
Visualizações
unknown type in catch at AXIOS request

I have created a custom error and set a custom message for it. then somewhere I throw my custom error and catch somewhere else. I want to access to message that I set before .but TypeScript tell me that error has unknown type! how can I fix it?

async activeAccount(uuid: string) {
  try {
    const response = await ApiClient(
      METHODS.GET,
      "Account/approveEmail",
      false,
      {
        uuid
      }
    );
  } catch (error) {
    this.showToastError(error.message);
  }
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

There is no guarantee that the thing caught by catch is actually an error because throw can throw anything (that's why the type is unknown, you have to narrow it with checks to do anything with it). The compiler is warning you appropriately that you are failing to consider something like this:


try {
    throw undefined;
} catch (err) {
    console.log(err.message); // oops
}

to fix this, you can add a check to make sure that you have an actual error:


try {
    ...
} catch (err) {
    if (err instanceof Error) {
        console.log(err.message); // ok
    }
}
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