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

111
Vistas
Keep getting Unhandled promise rejection even with try catch block

I keep getting the following error:

UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)

After looking up some solutions all I have to do is put my code within a try catch block, that you can see below but I still get this error, what am I doing wrong?

I am trying to update a column and set any arrays in it to an empty array.

Parse.Cloud.job("updateFollowedBy", async (request) => {
    try {
        var emptyArray = [];

        let date = new Date();
        let query = new Parse.Query("Categories");
    
        const results = await query.find({useMasterKey:true});
    
        results.forEach(object => {
            if (object.get("followedBy")) {
                object.set("followedBy", emptyArray);
            }
        });
        Parse.Object.saveAll(results);  
        return ("Successfully updated column on " + date); 
    } 
    catch(e) {
        console.log(e);
    }
});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The unhandled rejected promise probably comes from the Parse.Object.saveAll() function since you are not awaiting this. Try with:

Parse.Cloud.job("updateFollowedBy", async (request) => {
    try {
        var emptyArray = [];

        let date = new Date();
        let query = new Parse.Query("Categories");
    
        const results = await query.find({useMasterKey:true});
    
        results.forEach(object => {
            if (object.get("followedBy")) {
                object.set("followedBy", emptyArray);
            }
        });
        await Parse.Object.saveAll(results);
        // You might want to pass { useMasterKey: true } option to make it work without exception: 
        //await Parse.Object.saveAll(results, { useMasterKey: true });
        return ("Successfully updated column on " + date); 
    } 
    catch(e) {
        console.log(e);
    }
});
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