generated from nhcarrigan/template
28 lines
972 B
TypeScript
28 lines
972 B
TypeScript
/**
|
|
* @file Frontend error logging utility that forwards errors to the backend telemetry service.
|
|
* @copyright nhcarrigan
|
|
* @license Naomi's Public License
|
|
* @author Naomi Carrigan
|
|
*/
|
|
/* eslint-disable no-console -- Errors are forwarded to backend via the overridden console.error */
|
|
import { ValidationError } from "../api/client.js";
|
|
|
|
/**
|
|
* Logs an error to the backend telemetry service.
|
|
* ValidationErrors (4xx API rejections) are downgraded to console.warn so they
|
|
* are not forwarded to the error-email pipeline — they are expected server responses.
|
|
* @param logArguments - The values to log, forwarded directly to console.error or console.warn.
|
|
*/
|
|
const logError = (...logArguments: Array<unknown>): void => {
|
|
const isValidation = logArguments.some((argument) => {
|
|
return argument instanceof ValidationError;
|
|
});
|
|
if (isValidation) {
|
|
console.warn(...logArguments);
|
|
return;
|
|
}
|
|
console.error(...logArguments);
|
|
};
|
|
|
|
export { logError };
|