Show supervisor addon configuration error (#8950)

Co-authored-by: Bram Kragten <mail@bramkragten.nl>
This commit is contained in:
Joakim Sørensen 2021-05-05 10:26:11 +02:00 committed by GitHub
parent 23c1c2f5eb
commit 6e5e2625d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 12 deletions

View File

@ -262,6 +262,11 @@ class HassioAddonConfig extends LitElement {
private async _saveTapped(ev: CustomEvent): Promise<void> {
const button = ev.currentTarget as any;
const eventdata = {
success: true,
response: undefined,
path: "options",
};
button.progress = true;
this._error = undefined;
@ -272,23 +277,19 @@ class HassioAddonConfig extends LitElement {
});
this._configHasChanged = false;
const eventdata = {
success: true,
response: undefined,
path: "options",
};
fireEvent(this, "hass-api-called", eventdata);
if (this.addon?.state === "started") {
await suggestAddonRestart(this, this.hass, this.supervisor, this.addon);
}
} catch (err) {
this._error = this.supervisor.localize(
"addon.configuration.options.failed_to_save",
"addon.failed_to_save",
"error",
extractApiErrorMessage(err)
);
eventdata.success = false;
}
button.progress = false;
fireEvent(this, "hass-api-called", eventdata);
}
static get styles(): CSSResult[] {

View File

@ -191,6 +191,10 @@ class HassioAddonDashboard extends LitElement {
}
private async _apiCalled(ev): Promise<void> {
if (!ev.detail.success) {
return;
}
const pathSplit: string[] = ev.detail.path?.split("/");
if (!pathSplit || pathSplit.length === 0) {

View File

@ -2,7 +2,11 @@ import { atLeastVersion } from "../../common/config/version";
import { HaFormSchema } from "../../components/ha-form/ha-form";
import { HomeAssistant } from "../../types";
import { SupervisorArch } from "../supervisor/supervisor";
import { hassioApiResultExtractor, HassioResponse } from "./common";
import {
extractApiErrorMessage,
hassioApiResultExtractor,
HassioResponse,
} from "./common";
export type AddonStage = "stable" | "experimental" | "deprecated";
export type AddonAppArmour = "disable" | "default" | "profile";
@ -186,16 +190,20 @@ export const setHassioAddonOption = async (
data: HassioAddonSetOptionParams
) => {
if (atLeastVersion(hass.config.version, 2021, 2, 4)) {
await hass.callWS({
const response = await hass.callWS<HassioResponse<any>>({
type: "supervisor/api",
endpoint: `/addons/${slug}/options`,
method: "post",
data,
});
return;
if (response.result === "error") {
throw Error(extractApiErrorMessage(response));
}
return response;
}
await hass.callApi<HassioResponse<void>>(
return hass.callApi<HassioResponse<any>>(
"POST",
`hassio/addons/${slug}/options`,
data

View File

@ -3,7 +3,8 @@ import { HomeAssistant } from "../../types";
export interface HassioResponse<T> {
data: T;
result: "ok";
message?: string;
result: "ok" | "error";
}
export interface HassioStats {