@archon-inc/sdk
Version:
Integrate easily to our government platform using this SDK. More info on https://archon.inc/sdk
32 lines (31 loc) • 1.07 kB
JavaScript
import { Archon } from "../Archon.js";
import { Outcome, Severity } from "../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.
*/
export default async function logError(error, options) {
// if no severity is provided, default to error
if (options === undefined) {
options = {
eventType: "error",
outcome: Outcome.FAILURE
};
}
if (options.severity === undefined) {
options.severity = 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.request("/logging/log", "POST", { ...options, eventType: "error", source: Archon.getComponentName() })
.catch((err) => {
console.error(`Failed to log error: ${err}`);
});
}