'Error 0, logger 1.default) is not a function

This code was built to allow us to save errors to our database.

const logErrors = function (data) {
    try {
        let error = { date: new Date(), ...data };
        databaseConnections[dbMappings['BACKEND_ERROR_DB_MAPPING']['default']].collection('BackendLogs').insert(error);
    } catch (error) {
        const slackLog = new Log();
        slackLog.error(error.toString());
    }
};

export default logErrors;

The code works OK and saves errors to our database, but it occasionally throws the error "0, logger 1.default) is not a function."

What could be the problem?

Example scenario

catch (error) {
            // error.stack = error.stack + " " + JSON.stringify(this.data);
            if (error) {
                logErrors({ message: error }); <<<<<
            }
        }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source