Unhandled rejection warning when trying to pass Promise reject info from backend to frontend. How can I transfer this info?

Hi,
I’m trying to return custom messages to the frontend when getting specific errors, in this case when I find that a username is already taken. As i’ll be checking for multiple possible errors, I need to be able to specify the reason for the rejection. I added catch clauses in the backend, but the final catch doesn’t seem to be working. Any idea why?


export function doRegistration(email, password, emails, labels, userName) {
     return wixUsers.register(email, password, {
 "contactInfo": {
 "emails": emails,
             }
        })
        .then((results) => {
 let userNameLowCase = userName.toLowerCase();
 let userProfileToInsert = {
 "userName": userName,
 "userNameLowerCase": userNameLowCase,
 "_owner": results.user.id,
            };
             wixData.insert("userProfile", userProfileToInsert)
                .then((insertResult) => {
//skipped some irrelevant code here
                })
                .catch((err) => {
 let errorMsg = err;
                     console.error("error caught in the wixdatainsert catch of the register jsw");
                    console.error(errorMsg);
 return Promise.reject(err);
                });
        })
        .catch((errLevel2) => {
 let errorLevel2Msg = errLevel2;
             console.error("error caught in the catch of the register jsw");
            console.error(errorLevel2Msg);
 return Promise.reject(errLevel2);
        });
}

So the first catch and console.error do show the error I wanted to catch, but returning the promise.reject to the higher level catch doesn’t seem to work, and I don’t see the “level2” error. How can I pass on the rejection?

P.S.: Another oddity in this code, which I’ve already posted about (but not gotten replies) is that the _owner field isn’t getting populated, although it did work once… any idea why?

I now suspect that this is due to all rejects needing to be caught in the backend code. That would mean we need to resolve the promise, but still somehow pass the failure information to the frontend. how? I haven’t yet found a way that works.