How to throw error message from backend to frontend

Hi all. Made a custom sign up registration form for which the client will authenticate the user manually from the console.

I’m also passing on the successful data into another database which is working well.

The only thing that doesn’t seem to happen is when there is an error in the backend registration function, the error msg is not showing up.

What is the correct way to throw the error from the backend function to the frontend?

Sample code below.

// Velo API Reference: https://www.wix.com/velo/reference/api-overview/introduction
// FRONT END CODE
import wixData from 'wix-data';

import { authentication } from 'wix-members';
import { myRegisterMemberFunction } from 'backend/register';

import { myAssignRoleFunction } from 'backend/register';

$w.onReady(function () {

    $w("#button2").onClick((event) => {
        
        

            const name = $w('#input1').value;
            const password = $w('#input3').value;
            const roles = $w('#checkboxGroup1').value;
            console.log(roles);

            const email = $w('#input2').value;
            let options = {
                contactInfo: {
                    firstName: name,

                },
                privacyStatus: 'PUBLIC'
            }
           
            
            myRegisterMemberFunction(email, password, options)
                .then((result) => {
                   
                    const memberid = result.member._id;
                    const status = result.status;
                    console.log("member id" + memberid);

                   // result is successful. and data is inserted into another database. skipping irrelevant code

                })
                .catch((err) => {
                            let errorMsg = err;
                            console.log(errorMsg);
                            $w('#msgbox').text = errorMsg;
                          
                        });
    });
});

// BACKEND CODE

import { authentication } from 'wix-members-backend';
import { authorization } from 'wix-members-backend';

export function myRegisterMemberFunction(email, password, options) {
    console.log("backend register started");
    return authentication.register(email, password, options)
        .then((registrationResult) => {
            return registrationResult;
        })
        .catch((error) => {
           let erromsg = error.message
           console.error(erromsg);
           return errormsg
        })
}

return Promise.reject(errormsg);

Thanks JD. This worked.

Thanks!!