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

114
Vistas
Javascript - Best Practices Using Multiple try/catch within Asynchronous Functions

I've got two files containing asynchronous calls, wrapped in try/catches:

index.js

const fetchData = async () => {
    try {
        const data = await Service.getData()
    } catch (e) {
        // do some error handling
    }
}

Service.js

const Service = {
    getData: async () => {
        try {
            const data = await callApi()
        } catch (e) {
            // do some more error handling
        }
     }
 }

Is the try/catch necessary within fetchData(), since there's already a try/catch in getData()? i.e., is it enough to refactor like so...

const fetchData = async () => {
    const data = await Service.getData()
}

...while letting the service method do all the error handling?

I know this may be a simple question of how to scaffold error handling and personal preference, but I'm mostly looking for what others would implement to reduce boilerplate code

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

try cache block is only required in the Service as it is calling API which may return the error sometimes.

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