Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

96
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda