UNPKG

@lexamica-modules/job-queue

Version:

The package for the Lexamica Job Queue SDK powered by Redis and BullMQ

31 lines (30 loc) 1.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.handleErrorWithInfo = void 0; const logger_1 = require("@lexamica-modules/logger"); const logger = (0, logger_1.TaskLogger)(process.env.DATA_DOG_API_KEY ?? "", "Message-Queue", process.env.JOB_QUEUE_ENVIRONMENT, ""); // handle and log all uncaught errors process.on("uncaughtException", function (err) { logger.error(`An uncaught error occured in the @lexamica-modules/job-queue package: ${err}`); }); process.on("unhandledRejection", (reason, promise) => { logger.error(`An unhandled rejection occured in the @lexamica-modules/job-queue package: ${{ promise, reason, }}`); }); /** * This function logs out an error and optionally throws it further if specified * @param options * @param {string} options.message The error message to log * @param {string} options.job The job name or ID * @param {Error} options.error The actual error being handled * @param {boolean} options.handle Default to true, but if set to false, error will be thrown through once it has been logged. */ function handleErrorWithInfo({ message, job, error, handle = true, }) { logger.error(`Message Queue Job: ${job} | Message: ${message} | Error: ${error}`); if (!handle) { throw error; } } exports.handleErrorWithInfo = handleErrorWithInfo;