fix(query): preserve structured backend errors
This commit is contained in:
1 parent
2e9dcdc26b
commit
bcafc4a474
58 files changed
+4182
-554
No files matched your search
@@ -1,3 +1,5 @@
|
||||
import { normalizeBackendError, type BackendError } from "@/lib/backend/errorUtils";
|
||||
|
||||
/**
|
||||
* Minimal shape of a translate function, satisfied by both `useI18n().t` inside
|
||||
* components and `i18n.global.t` in stores and composables. Using the full
|
||||
@@ -118,7 +120,17 @@ function backendErrorMessage(error: unknown): string {
|
||||
return String(error);
|
||||
}
|
||||
|
||||
function translateStructuredBackendError(t: BackendErrorTranslate, error: BackendError): string {
|
||||
const translated = t(error.messageKey, error.messageParams);
|
||||
const summary = translated !== error.messageKey ? translated : t("backendErrors.unknown");
|
||||
const detail = error.detail?.trim();
|
||||
return detail && detail !== summary ? `${summary}\n\n${detail}` : summary;
|
||||
}
|
||||
|
||||
export function translateBackendError(t: BackendErrorTranslate, error: unknown): string {
|
||||
const structured = normalizeBackendError(error);
|
||||
if (structured) return translateStructuredBackendError(t, structured);
|
||||
|
||||
const message = backendErrorMessage(error);
|
||||
const tagged = message.match(/^\[([A-Za-z][A-Za-z0-9]+)\]\s*([\s\S]*)$/);
|
||||
if (tagged) {
|
||||
|
||||
Reference in new issue
Block a user