Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

109
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!