Skip to content

Fix using "extractApiErrorMessage" in error-log-card w/o supervisor #24732

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/data/hassio/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,20 @@ export interface HassioStats {
export const hassioApiResultExtractor = <T>(response: HassioResponse<T>) =>
response.data;

export const extractApiErrorMessage = (error: any): string =>
typeof error === "object"
export const extractApiErrorMessage = (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is code from the supervisor, it lives in data/hassio, if we want to make it more generic we should move it out of the code for supervisor.

error: any,
isSupervisor?: boolean
): string => {
let errorMessage;
if (isSupervisor ?? true) errorMessage = "Unknown error, see supervisor logs";
else errorMessage = "Unknown error";

return typeof error === "object"
? typeof error.body === "object"
? error.body.message || "Unknown error, see supervisor logs"
: error.body || error.message || "Unknown error, see supervisor logs"
? error.body.message || errorMessage
: error.body || error.message || errorMessage
: error;
};

const ignoredStatusCodes = new Set([502, 503, 504]);

Expand Down
5 changes: 4 additions & 1 deletion src/panels/config/logs/error-log-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,10 @@ class ErrorLogCard extends LitElement {
"ui.panel.config.logs.failed_get_logs",
{
provider: this.provider,
error: extractApiErrorMessage(err),
error: extractApiErrorMessage(
err,
isComponentLoaded(this.hass, "hassio")
),
}
);
}
Expand Down
Loading