fix: Substantially reduce cases where errors block whole card (#1764)

This commit is contained in:
Dermot Duffy
2024-12-15 20:39:18 -08:00
committed by GitHub
parent b6fb821074
commit dab9ff3045
25 changed files with 329 additions and 407 deletions
+5 -6
View File
@@ -1,9 +1,6 @@
import { Task } from '@lit-labs/task';
import { html, TemplateResult } from 'lit';
import {
dispatchFrigateCardErrorEvent,
renderProgressIndicator,
} from '../components/message';
import { renderProgressIndicator } from '../components/message';
import { CardWideConfig } from '../config/types';
import { errorToConsole } from './basic';
@@ -16,12 +13,12 @@ import { errorToConsole } from './basic';
* @returns A template.
*/
export const renderTask = <R>(
host: EventTarget,
task: Task<unknown[], R>,
completeFunc: (result: R) => TemplateResult | void,
options?: {
cardWideConfig?: CardWideConfig;
inProgressFunc?: () => TemplateResult | void;
errorFunc?: (e: Error) => void;
},
): TemplateResult => {
const progressConfig = {
@@ -34,7 +31,9 @@ export const renderTask = <R>(
options?.inProgressFunc?.() ?? renderProgressIndicator(progressConfig),
error: (e: unknown) => {
errorToConsole(e as Error);
dispatchFrigateCardErrorEvent(host, e as Error);
if (options?.errorFunc) {
options.errorFunc(e as Error);
}
},
complete: completeFunc,
})}`;