fix: Substantially reduce cases where errors block whole card (#1764)
This commit is contained in:
+2
-11
@@ -1,12 +1,9 @@
|
||||
import { CameraEndpoint } from '../camera-manager/types';
|
||||
import { dispatchErrorMessageEvent } from '../components/message';
|
||||
import { localize } from '../localize/localize';
|
||||
import { ExtendedHomeAssistant } from '../types';
|
||||
import { errorToConsole } from './basic';
|
||||
import { homeAssistantSignPath } from './ha';
|
||||
|
||||
export const getEndpointAddressOrDispatchError = async (
|
||||
element: HTMLElement,
|
||||
export const convertEndpointAddressToSignedWebsocket = async (
|
||||
hass: ExtendedHomeAssistant,
|
||||
endpoint: CameraEndpoint,
|
||||
expires?: number,
|
||||
@@ -20,13 +17,7 @@ export const getEndpointAddressOrDispatchError = async (
|
||||
response = await homeAssistantSignPath(hass, endpoint.endpoint, expires);
|
||||
} catch (e) {
|
||||
errorToConsole(e as Error);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!response) {
|
||||
dispatchErrorMessageEvent(element, localize('error.failed_sign'));
|
||||
return null;
|
||||
}
|
||||
|
||||
return response.replace(/^http/i, 'ws');
|
||||
return response ? response.replace(/^http/i, 'ws') : null;
|
||||
};
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
import { HomeAssistant } from '@dermotduffy/custom-card-helpers';
|
||||
import { HassEntity } from 'home-assistant-js-websocket';
|
||||
import { CameraConfig } from '../config/types.js';
|
||||
import { dispatchErrorMessageEvent } from '../components/message.js';
|
||||
import { localize } from '../localize/localize.js';
|
||||
|
||||
/**
|
||||
* Get the state object or dispatch an error. Used in `ha` and `image` live
|
||||
* providers.
|
||||
* @param element HTMLElement to dispatch errors from.
|
||||
* @param hass Home Assistant object.
|
||||
* @param cameraConfig Camera configuration.
|
||||
* @returns
|
||||
*/
|
||||
export const getStateObjOrDispatchError = (
|
||||
element: HTMLElement,
|
||||
hass: HomeAssistant,
|
||||
cameraConfig?: CameraConfig,
|
||||
): HassEntity | null => {
|
||||
if (!cameraConfig?.camera_entity) {
|
||||
dispatchErrorMessageEvent(element, localize('error.no_live_camera'), {
|
||||
context: cameraConfig,
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
const stateObj = hass.states[cameraConfig.camera_entity];
|
||||
if (!stateObj) {
|
||||
dispatchErrorMessageEvent(element, localize('error.live_camera_not_found'), {
|
||||
context: cameraConfig,
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
return stateObj;
|
||||
};
|
||||
+5
-6
@@ -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,
|
||||
})}`;
|
||||
|
||||
@@ -43,7 +43,8 @@ const fetchThumbnail = async (
|
||||
};
|
||||
reader.onerror = (e) => reject(e);
|
||||
reader.readAsDataURL(blob);
|
||||
});
|
||||
})
|
||||
.catch((e) => reject(e));
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user