feat(web): shared status-aware error-message helper + MutationError component (#63)
This commit is contained in:
@@ -6,20 +6,15 @@ import {
|
||||
|
||||
import i18n from "../i18n";
|
||||
import { toastManager } from "../toast/toast-manager";
|
||||
import { HttpError, InUseError } from "./queries";
|
||||
import { errorMessageKey } from "./error-message";
|
||||
|
||||
function mutationErrorMessage(
|
||||
error: unknown,
|
||||
meta: MutationMeta | undefined,
|
||||
): string {
|
||||
if (meta?.errorMessage) return i18n.t(meta.errorMessage);
|
||||
if (error instanceof InUseError) {
|
||||
return i18n.t("actions.inUse", { count: error.count });
|
||||
}
|
||||
if (error instanceof HttpError && error.status === 503) {
|
||||
return i18n.t("search.unavailable");
|
||||
}
|
||||
return i18n.t("toast.error");
|
||||
const { key, opts } = errorMessageKey(error);
|
||||
return i18n.t(key, opts);
|
||||
}
|
||||
|
||||
/** Builds the app's QueryClient, including the MutationCache that bridges every
|
||||
|
||||
Reference in New Issue
Block a user