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

149
Visualizações
Am getting UnhandledPromiseRejectionWarning in try catch block with async await

While implementing a graphql resolver function, I ran into an UnhandledPromiseRejectionWarning error. Am sending a request to classify some text and it's the classification that's throwing an error. I want to re-throw whatever error is thrown, but the error is not being caught in the catch block.

Am not awaiting the request because I am sending two other requests with the classify request in parallel, but am awaiting each request in a Promise.all function.

Here is the code:

createPost: async (
        _,
        { fields: { media, text, location } }) => {
        try {
            const firstRequest = languageClient.classifyText({
                document: {
                    content: text,
                    type: 'PLAIN_TEXT'
                }
            });
        const secondRequest = // another request
        const thirdRequest = // another request
        const result = await Promise.all([firstRequest, secondRequest, thirdRequest]);
    } catch(error) { throw error }
    
}

How do I handle the error properly?

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

0

Stupid me, I wrapped the Promise.all with an if statement, so it's not even running at all. That's the reason why am getting weird results. I just discovered this after 3 days. I'm so stupid.

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