UNPKG

@archon-inc/sdk

Version:

Integrate easily to our government platform using this SDK. More info on https://archon.inc/sdk

35 lines (34 loc) 1.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = logError; const Archon_js_1 = require("../Archon.js"); const logging_js_1 = require("../types/logging.js"); /** * Log an error that occurs in your application. * @param error The error that occurred. * @param options Options to include with the log message. */ async function logError(error, options) { // if no severity is provided, default to error if (options === undefined) { options = { eventType: "error", outcome: logging_js_1.Outcome.FAILURE }; } if (options.severity === undefined) { options.severity = logging_js_1.Severity.ERROR; } if (options.context === undefined) { options.context = `${error.name} - ${error.message}`; } else { options.context = `${error.name} - ${error.message}: ${options.context}`; } if (error.stack) options.context += `\n${error.stack}`; Archon_js_1.Archon.request("/logging/log", "POST", { ...options, eventType: "error", source: Archon_js_1.Archon.getComponentName() }) .catch((err) => { console.error(`Failed to log error: ${err}`); }); }