UNPKG

node-huntglitch

Version:

A lightweight utility to send error logs to the HuntGlitch logging service.

52 lines (51 loc) 1.84 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Log = void 0; const axios_1 = __importDefault(require("axios")); const Log = ({ error, method, endPoint, requestIp, headers, logType }) => { return new Promise((resolve, reject) => { var _a; if (!process.env.PROJECT_KEY || !process.env.DELIVERABLE_KEY) { reject("PROJECT_KEY or DELIVERABLE_KEY is not defined in .env file"); return; } if (!error || !endPoint || !method || !requestIp) { reject("Missing 'error' or 'method' or 'endPoint' or 'requestIp'"); return; } const match = (_a = error.stack) === null || _a === void 0 ? void 0 : _a.match(/\/([\w\-_.]+\.js):(\d+):(\d+)/); const [, filename, , column] = match || []; const body = { vp: process.env.PROJECT_KEY, vd: process.env.DELIVERABLE_KEY, o: logType !== null && logType !== void 0 ? logType : 5, a: JSON.stringify({ b: { c: error.message, d: filename, f: column, g: 0, h: "Error" }, i: error.stack, k: headers, m: endPoint, n: method, j: process.versions }), r: requestIp }; axios_1.default .post("https://api.huntglitch.com/add-log", body, { headers: { "Content-Type": "application/json" } }) .then(resolve) .catch(reject); }); }; exports.Log = Log;