feat(client): improve error message for HTTP errors

This commit is contained in:
Elian Doran 2025-12-06 22:12:06 +02:00
parent 036f8e49a4
commit 230def10fe
No known key found for this signature in database
2 changed files with 11 additions and 4 deletions

View File

@ -263,7 +263,7 @@ async function reportError(method: string, url: string, statusCode: number, resp
const toastService = (await import("./toast.js")).default;
const messageStr = typeof message === "string" ? message : JSON.stringify(message);
const messageStr = (typeof message === "string" ? message : JSON.stringify(message)) || "-";
if ([400, 404].includes(statusCode) && response && typeof response === "object") {
toastService.showError(messageStr);
@ -274,10 +274,13 @@ async function reportError(method: string, url: string, statusCode: number, resp
...response
});
} else {
const title = `${statusCode} ${method} ${url}`;
toastService.showErrorTitleAndMessage(title, messageStr);
const { t } = await import("./i18n.js");
toastService.showErrorTitleAndMessage(
t("server.unknown_http_error_title"),
t("server.unknown_http_error_content", { statusCode, method, url, message: messageStr }),
15_000);
const { throwError } = await import("./ws.js");
throwError(`${title} - ${message}`);
throwError(`${statusCode} ${method} ${url} - ${message}`);
}
}

View File

@ -2107,5 +2107,9 @@
},
"popup-editor": {
"maximize": "Switch to full editor"
},
"server": {
"unknown_http_error_title": "Communication error with the server",
"unknown_http_error_content": "Status code: {{statusCode}}\nURL: {{method}} {{url}}\nMessage: {{message}}"
}
}