Make error handling and console logging consistent

This commit is contained in:
Dermot Duffy
2022-06-20 03:03:27 +00:00
parent bd393d953a
commit 4901905ca1
11 changed files with 132 additions and 99 deletions
+17
View File
@@ -1,4 +1,5 @@
import { isEqual } from 'lodash-es';
import { FrigateCardError } from '../types';
/**
* Dispatch a Frigate Card event.
@@ -60,3 +61,19 @@ export function arrayMove(target: unknown[], from: number, to: number): void {
export function contentsChanged(n: unknown, o: unknown): boolean {
return !isEqual(n, o);
}
/**
* Log an error as a warning to the console.
* @param e The Error object.
* @param func The Console func to call.
*/
export function errorToConsole(e: Error, func?: CallableFunction): void {
if (!func) {
func = console.warn;
}
if (e instanceof FrigateCardError && e.context) {
func(e, e.context);
} else {
func(e);
}
}