feat: Add hardened error handling and retries (#2451)
- Closes #1830 - Closes #2099
This commit is contained in:
committed by
dermotduffy
parent
4bc787e2b7
commit
47bcce93d3
@@ -8,8 +8,8 @@ import {
|
||||
} from 'lit';
|
||||
import { customElement, property, state } from 'lit/decorators.js';
|
||||
import { isEqual } from 'lodash-es';
|
||||
import { IssueTriggerEventData } from '../card-controller/issues/types.js';
|
||||
import { TemplateRenderer } from '../card-controller/templates/index.js';
|
||||
import { dispatchAdvancedCameraCardErrorEvent } from '../components-lib/message/dispatch.js';
|
||||
import { ConditionsManager } from '../conditions/conditions-manager.js';
|
||||
import { getConditionStateManagerViaEvent } from '../conditions/state-manager-via-event.js';
|
||||
import { ConditionStateManager } from '../conditions/state-manager.js';
|
||||
@@ -35,6 +35,12 @@ import { AdvancedCameraCardError } from '../types.js';
|
||||
import { errorToConsole } from '../utils/basic.js';
|
||||
import { fireAdvancedCameraCardEvent } from '../utils/fire-advanced-camera-card-event.js';
|
||||
|
||||
class ElementsCreationError extends AdvancedCameraCardError {
|
||||
constructor(context?: unknown) {
|
||||
super(localize('error.could_not_create_elements'), context);
|
||||
}
|
||||
}
|
||||
|
||||
/* A note on picture element rendering:
|
||||
*
|
||||
* To avoid needing to deal with the rendering of all the picture elements
|
||||
@@ -106,7 +112,7 @@ export class AdvancedCameraCardElementsCore extends LitElement {
|
||||
private _createRoot(): HuiConditionalElement {
|
||||
const elementConstructor = customElements.get('hui-conditional-element');
|
||||
if (!elementConstructor || !this.hass) {
|
||||
throw new Error(localize('error.could_not_render_elements'));
|
||||
throw new ElementsCreationError(this._renderedElements);
|
||||
}
|
||||
|
||||
const element = new elementConstructor() as HuiConditionalElement;
|
||||
@@ -145,7 +151,11 @@ export class AdvancedCameraCardElementsCore extends LitElement {
|
||||
this._renderedElements = elements;
|
||||
this._root = this._createRoot();
|
||||
} catch (e) {
|
||||
return dispatchAdvancedCameraCardErrorEvent(this, e as AdvancedCameraCardError);
|
||||
errorToConsole(e as Error);
|
||||
fireAdvancedCameraCardEvent<IssueTriggerEventData>(this, 'issue:trigger', {
|
||||
key: 'config_error',
|
||||
error: new ElementsCreationError(elements),
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user