Make error handling and console logging consistent
This commit is contained in:
+22
-18
@@ -9,7 +9,7 @@ import {
|
||||
LitElement,
|
||||
PropertyValues,
|
||||
TemplateResult,
|
||||
unsafeCSS
|
||||
unsafeCSS,
|
||||
} from 'lit';
|
||||
import { customElement, property, state } from 'lit/decorators.js';
|
||||
import { createRef, Ref, ref } from 'lit/directives/ref.js';
|
||||
@@ -33,16 +33,16 @@ import {
|
||||
LiveProvider,
|
||||
MediaShowInfo,
|
||||
TransitionEffect,
|
||||
WebRTCCardConfig
|
||||
WebRTCCardConfig,
|
||||
} from '../types.js';
|
||||
import { stopEventFromActivatingCardWideActions } from '../utils/action.js';
|
||||
import { contentsChanged } from '../utils/basic.js';
|
||||
import { contentsChanged, errorToConsole } from '../utils/basic.js';
|
||||
import { getCameraIcon, getCameraTitle } from '../utils/camera.js';
|
||||
import { homeAssistantSignPath } from '../utils/ha';
|
||||
import { getFullDependentBrowseMediaQueryParameters } from '../utils/ha/browse-media.js';
|
||||
import {
|
||||
dispatchExistingMediaShowInfoAsEvent,
|
||||
dispatchMediaShowEvent
|
||||
dispatchMediaShowEvent,
|
||||
} from '../utils/media-info.js';
|
||||
import { View } from '../view.js';
|
||||
import { AutoMediaPlugin, AutoMediaPluginType } from './embla-plugins/automedia.js';
|
||||
@@ -52,8 +52,8 @@ import { dispatchErrorMessageEvent } from './message.js';
|
||||
import './next-prev-control.js';
|
||||
import { FrigateCardNextPreviousControl } from './next-prev-control.js';
|
||||
import './title-control.js';
|
||||
import "./surround-thumbnails";
|
||||
import "../patches/ha-camera-stream";
|
||||
import './surround-thumbnails';
|
||||
import '../patches/ha-camera-stream';
|
||||
|
||||
// Number of seconds a signed URL is valid for.
|
||||
const URL_SIGN_EXPIRY_SECONDS = 24 * 60 * 60;
|
||||
@@ -913,7 +913,7 @@ export class FrigateCardLiveWebRTCCard extends LitElement {
|
||||
// Set the id to ensure that the relevant CSS styles will have
|
||||
// sufficient specifity to overcome some styles that are otherwise
|
||||
// applied to <ha-card> in Safari.
|
||||
webrtcElement.id = "webrtc";
|
||||
webrtcElement.id = 'webrtc';
|
||||
}
|
||||
return html`${webrtcElement}`;
|
||||
};
|
||||
@@ -1021,7 +1021,11 @@ export class FrigateCardLiveJSMPEG extends LitElement {
|
||||
* @returns A URL or null.
|
||||
*/
|
||||
protected async _getURL(): Promise<string | null> {
|
||||
if (!this.hass || !this.cameraConfig?.frigate.client_id || !this.cameraConfig?.frigate.camera_name) {
|
||||
if (
|
||||
!this.hass ||
|
||||
!this.cameraConfig?.frigate.client_id ||
|
||||
!this.cameraConfig?.frigate.camera_name
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1033,8 +1037,8 @@ export class FrigateCardLiveJSMPEG extends LitElement {
|
||||
`/jsmpeg/${this.cameraConfig.frigate.camera_name}`,
|
||||
URL_SIGN_EXPIRY_SECONDS,
|
||||
);
|
||||
} catch (err) {
|
||||
console.warn(err);
|
||||
} catch (e) {
|
||||
errorToConsole(e as Error);
|
||||
return null;
|
||||
}
|
||||
if (!response) {
|
||||
@@ -1182,12 +1186,12 @@ export class FrigateCardLiveJSMPEG extends LitElement {
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
"frigate-card-live-jsmpeg": FrigateCardLiveJSMPEG
|
||||
"frigate-card-live-webrtc-card": FrigateCardLiveWebRTCCard
|
||||
"frigate-card-live-ha": FrigateCardLiveFrigate
|
||||
"frigate-card-live-provider": FrigateCardLiveProvider
|
||||
"frigate-card-live-carousel": FrigateCardLiveCarousel
|
||||
"frigate-card-live": FrigateCardLive
|
||||
}
|
||||
interface HTMLElementTagNameMap {
|
||||
'frigate-card-live-jsmpeg': FrigateCardLiveJSMPEG;
|
||||
'frigate-card-live-webrtc-card': FrigateCardLiveWebRTCCard;
|
||||
'frigate-card-live-ha': FrigateCardLiveFrigate;
|
||||
'frigate-card-live-provider': FrigateCardLiveProvider;
|
||||
'frigate-card-live-carousel': FrigateCardLiveCarousel;
|
||||
'frigate-card-live': FrigateCardLive;
|
||||
}
|
||||
}
|
||||
|
||||
+19
-16
@@ -6,7 +6,7 @@ import {
|
||||
fromUnixTime,
|
||||
getUnixTime,
|
||||
startOfHour,
|
||||
sub
|
||||
sub,
|
||||
} from 'date-fns';
|
||||
import {
|
||||
CSSResultGroup,
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
LitElement,
|
||||
PropertyValues,
|
||||
TemplateResult,
|
||||
unsafeCSS
|
||||
unsafeCSS,
|
||||
} from 'lit';
|
||||
import { customElement, property } from 'lit/decorators.js';
|
||||
import { classMap } from 'lit/directives/class-map.js';
|
||||
@@ -28,7 +28,7 @@ import {
|
||||
TimelineItem,
|
||||
TimelineOptions,
|
||||
TimelineOptionsCluster,
|
||||
TimelineWindow
|
||||
TimelineWindow,
|
||||
} from 'vis-timeline/esnext';
|
||||
import { CAMERA_BIRDSEYE } from '../const';
|
||||
import { localize } from '../localize/localize';
|
||||
@@ -42,10 +42,10 @@ import {
|
||||
frigateCardConfigDefaults,
|
||||
FrigateCardError,
|
||||
FrigateEvent,
|
||||
TimelineConfig
|
||||
TimelineConfig,
|
||||
} from '../types';
|
||||
import { stopEventFromActivatingCardWideActions } from '../utils/action';
|
||||
import { dispatchFrigateCardEvent, prettifyTitle } from '../utils/basic';
|
||||
import { dispatchFrigateCardEvent, errorToConsole, prettifyTitle } from '../utils/basic';
|
||||
import { getCameraTitle } from '../utils/camera.js';
|
||||
import {
|
||||
getRecordingSegments,
|
||||
@@ -53,7 +53,7 @@ import {
|
||||
getUniqueFrigateCameraEventsID,
|
||||
getUniqueFrigateCameraID,
|
||||
RecordingSegments,
|
||||
RecordingSummary
|
||||
RecordingSummary,
|
||||
} from '../utils/frigate';
|
||||
import {
|
||||
createEventParentForChildren,
|
||||
@@ -61,7 +61,7 @@ import {
|
||||
generateRecordingIdentifier,
|
||||
getBrowseMediaQueryParameters,
|
||||
isTrueMedia,
|
||||
multipleBrowseMediaQuery
|
||||
multipleBrowseMediaQuery,
|
||||
} from '../utils/ha/browse-media';
|
||||
import { View, ViewContext } from '../view';
|
||||
import { dispatchFrigateCardErrorEvent, dispatchMessageEvent } from './message.js';
|
||||
@@ -300,7 +300,7 @@ class TimelineDataManager {
|
||||
this._dateStart,
|
||||
this._dateEnd,
|
||||
),
|
||||
...(recordings ? [this._fetchRecordings(element, hass, cameras)] : []),
|
||||
...(recordings ? [this._fetchRecordings(hass, cameras)] : []),
|
||||
]);
|
||||
|
||||
return true;
|
||||
@@ -315,7 +315,6 @@ class TimelineDataManager {
|
||||
* @param end Fetch events that start earlier than this date.
|
||||
*/
|
||||
protected async _fetchRecordings(
|
||||
element: HTMLElement,
|
||||
hass: ExtendedHomeAssistant,
|
||||
cameras: Map<string, CameraConfig>,
|
||||
): Promise<void> {
|
||||
@@ -329,7 +328,7 @@ class TimelineDataManager {
|
||||
if (!config.frigate.camera_name) {
|
||||
return;
|
||||
}
|
||||
let summary: RecordingSummary;
|
||||
let summary: RecordingSummary = [];
|
||||
try {
|
||||
summary = await getRecordingsSummary(
|
||||
hass,
|
||||
@@ -337,7 +336,9 @@ class TimelineDataManager {
|
||||
config.frigate.camera_name,
|
||||
);
|
||||
} catch (e) {
|
||||
return dispatchFrigateCardErrorEvent(element, e as FrigateCardError);
|
||||
// Recording failure should not disrupt the rest of the timeline
|
||||
// experience.
|
||||
errorToConsole(e as Error);
|
||||
}
|
||||
|
||||
for (const dayData of summary) {
|
||||
@@ -691,7 +692,9 @@ export class FrigateCardTimelineCore extends LitElement {
|
||||
),
|
||||
]);
|
||||
results.set(camera, { segments: cameraResults[0], summary: cameraResults[1] });
|
||||
} catch (e) {}
|
||||
} catch (e) {
|
||||
errorToConsole(e as Error);
|
||||
}
|
||||
};
|
||||
const cameras = camera ? [camera] : [...(this.cameras?.keys() ?? [])];
|
||||
await Promise.all(cameras.map((camera) => fetch(camera, this.cameras?.get(camera))));
|
||||
@@ -1239,8 +1242,8 @@ export class FrigateCardTimelineCore extends LitElement {
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
"frigate-card-timeline-core": FrigateCardTimelineCore
|
||||
"frigate-card-timeline": FrigateCardTimeline
|
||||
}
|
||||
interface HTMLElementTagNameMap {
|
||||
'frigate-card-timeline-core': FrigateCardTimelineCore;
|
||||
'frigate-card-timeline': FrigateCardTimeline;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user