How to get more specific error message login from backend?

Hi,

I am trying to log in users in the backend and then pass session token on success to front end. On error I am trying to throw the error. However, for both register as well as login functions, all errors only produce a very generic error - “Error: Unable to handle the request, contact site administrator”

How can I create differentiated error messages so that I can handle them accordingly to the end user? My backend code snippet is below

return wixUsersBackend.login(email, password)
        .then((code)=>{
                return code
        }).catch((err)=>{
                 throw err
        })

When I run the same steps in the front end, I get differentiated error messages. But I want to do this in the backend, because I am also doing some dB transactions on register.

The same here…

Hi, I found a way to solve this, you can use an array for error as I showed in this example

//in your backend
    
export function loginFunc(email, password){
    return wixUsersBackend.login(email, password)
        .then((code)=>{
            return code
        }).catch((err) =>{
            [
            new Error(),
            "your desired type of error"
            ]
        })
    }
//in client site
let errorMsg

loginFunc().then( (code) => {
    //how you handle the code
    }).catch((err) => {
        errorMsg = err[1]
        //now you can handle the error depend on the messages you pass from backend
        console.log(errorMsg)
    })

    
/* the result in your console when error occurs will be

"your desired type of error"

*/