mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 09:16:38 +00:00
More consistant ignoring errors (#8553)
This commit is contained in:
parent
0ca2cdfbed
commit
d715867b09
@ -19,7 +19,7 @@ import "../../../src/components/ha-svg-icon";
|
|||||||
import {
|
import {
|
||||||
extractApiErrorMessage,
|
extractApiErrorMessage,
|
||||||
HassioResponse,
|
HassioResponse,
|
||||||
ignoredStatusCodes,
|
ignoreSupervisorError,
|
||||||
} from "../../../src/data/hassio/common";
|
} from "../../../src/data/hassio/common";
|
||||||
import { HassioHassOSInfo } from "../../../src/data/hassio/host";
|
import { HassioHassOSInfo } from "../../../src/data/hassio/host";
|
||||||
import {
|
import {
|
||||||
@ -216,11 +216,7 @@ export class HassioUpdate extends LitElement {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Only show an error if the status code was not expected (user behind proxy)
|
// Only show an error if the status code was not expected (user behind proxy)
|
||||||
// or no status at all(connection terminated)
|
// or no status at all(connection terminated)
|
||||||
if (
|
if (this.hass.connection.connected && !ignoreSupervisorError(err)) {
|
||||||
this.hass.connection.connected &&
|
|
||||||
err.status_code &&
|
|
||||||
!ignoredStatusCodes.has(err.status_code)
|
|
||||||
) {
|
|
||||||
showAlertDialog(this, {
|
showAlertDialog(this, {
|
||||||
title: this.supervisor.localize("common.error.update_failed"),
|
title: this.supervisor.localize("common.error.update_failed"),
|
||||||
text: extractApiErrorMessage(err),
|
text: extractApiErrorMessage(err),
|
||||||
|
@ -14,7 +14,10 @@ import "../../../../src/components/ha-dialog";
|
|||||||
import "../../../../src/components/ha-settings-row";
|
import "../../../../src/components/ha-settings-row";
|
||||||
import "../../../../src/components/ha-svg-icon";
|
import "../../../../src/components/ha-svg-icon";
|
||||||
import "../../../../src/components/ha-switch";
|
import "../../../../src/components/ha-switch";
|
||||||
import { extractApiErrorMessage } from "../../../../src/data/hassio/common";
|
import {
|
||||||
|
extractApiErrorMessage,
|
||||||
|
ignoreSupervisorError,
|
||||||
|
} from "../../../../src/data/hassio/common";
|
||||||
import { createHassioPartialSnapshot } from "../../../../src/data/hassio/snapshot";
|
import { createHassioPartialSnapshot } from "../../../../src/data/hassio/snapshot";
|
||||||
import { haStyle, haStyleDialog } from "../../../../src/resources/styles";
|
import { haStyle, haStyleDialog } from "../../../../src/resources/styles";
|
||||||
import type { HomeAssistant } from "../../../../src/types";
|
import type { HomeAssistant } from "../../../../src/types";
|
||||||
@ -160,7 +163,9 @@ class DialogSupervisorUpdate extends LitElement {
|
|||||||
try {
|
try {
|
||||||
await this._dialogParams!.updateHandler!();
|
await this._dialogParams!.updateHandler!();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
if (this.hass.connection.connected && !ignoreSupervisorError(err)) {
|
||||||
this._error = extractApiErrorMessage(err);
|
this._error = extractApiErrorMessage(err);
|
||||||
|
}
|
||||||
this._action = null;
|
this._action = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ import "../../../src/components/ha-card";
|
|||||||
import "../../../src/components/ha-settings-row";
|
import "../../../src/components/ha-settings-row";
|
||||||
import {
|
import {
|
||||||
extractApiErrorMessage,
|
extractApiErrorMessage,
|
||||||
ignoredStatusCodes,
|
ignoreSupervisorError,
|
||||||
} from "../../../src/data/hassio/common";
|
} from "../../../src/data/hassio/common";
|
||||||
import { fetchHassioHardwareInfo } from "../../../src/data/hassio/hardware";
|
import { fetchHassioHardwareInfo } from "../../../src/data/hassio/hardware";
|
||||||
import {
|
import {
|
||||||
@ -274,7 +274,7 @@ class HassioHostInfo extends LitElement {
|
|||||||
await rebootHost(this.hass);
|
await rebootHost(this.hass);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Ignore connection errors, these are all expected
|
// Ignore connection errors, these are all expected
|
||||||
if (err.status_code && !ignoredStatusCodes.has(err.status_code)) {
|
if (this.hass.connection.connected && !ignoreSupervisorError(err)) {
|
||||||
showAlertDialog(this, {
|
showAlertDialog(this, {
|
||||||
title: this.supervisor.localize("system.host.failed_to_reboot"),
|
title: this.supervisor.localize("system.host.failed_to_reboot"),
|
||||||
text: extractApiErrorMessage(err),
|
text: extractApiErrorMessage(err),
|
||||||
@ -304,7 +304,7 @@ class HassioHostInfo extends LitElement {
|
|||||||
await shutdownHost(this.hass);
|
await shutdownHost(this.hass);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Ignore connection errors, these are all expected
|
// Ignore connection errors, these are all expected
|
||||||
if (err.status_code && !ignoredStatusCodes.has(err.status_code)) {
|
if (this.hass.connection.connected && !ignoreSupervisorError(err)) {
|
||||||
showAlertDialog(this, {
|
showAlertDialog(this, {
|
||||||
title: this.supervisor.localize("system.host.failed_to_shutdown"),
|
title: this.supervisor.localize("system.host.failed_to_shutdown"),
|
||||||
text: extractApiErrorMessage(err),
|
text: extractApiErrorMessage(err),
|
||||||
|
@ -28,7 +28,22 @@ export const extractApiErrorMessage = (error: any): string => {
|
|||||||
: error;
|
: error;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const ignoredStatusCodes = new Set([502, 503, 504]);
|
const ignoredStatusCodes = new Set([502, 503, 504]);
|
||||||
|
|
||||||
|
export const ignoreSupervisorError = (error): boolean => {
|
||||||
|
if (error && error.status_code && ignoredStatusCodes.has(error.status_code)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
error &&
|
||||||
|
error.message &&
|
||||||
|
(error.message.includes("ERR_CONNECTION_CLOSED") ||
|
||||||
|
error.message.includes("ERR_CONNECTION_RESET"))
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
export const fetchHassioStats = async (
|
export const fetchHassioStats = async (
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user