refactor: enforce enum machine codes #18
Frontend verify / commits (push) Skipped
Frontend verify / security (push) Successful in 11s
Frontend verify / verify (push) Successful in 9m31s

Use owner enums for known codes; preserve wire values and unknown fallbacks.

Verified npm ci and verify: 379 tests, 5 lint checks, app and Storybook builds.
This commit was merged in pull request #41.
This commit is contained in:
2026-09-28 16:36:40 +03:00
committed by ksv741
parent 12c3b72bfb
commit 5b69003516
26 changed files with 248 additions and 79 deletions
@@ -13,13 +13,15 @@ import { useEffect, useRef, useState } from "react";
import { useForm } from "react-hook-form";
import { useTranslation } from "react-i18next";
import { apiErrorCode, apiQueryClient } from "@/shared/api";
import { ApiErrorCode, apiErrorCode, apiQueryClient, isApiErrorCode } from "@/shared/api";
import {
commitTbankConnectionBoundary,
type TbankConnectionStatus,
} from "../../model/connection-boundary";
enum ConnectionErrorCode { RequestFailed = "REQUEST_ERROR" }
type TbankConnectionSectionLoadedProps = {
refreshError: boolean;
refreshing: boolean;
@@ -43,7 +45,7 @@ const TbankConnectionSectionLoaded: FC<TbankConnectionSectionLoadedProps> = (
reset,
} = useForm<{ token: string }>();
const update = apiQueryClient.useMutation("put", "/api/v1/tbank-connection", {
onError: error => setRequestError(apiErrorCode(error) ?? "REQUEST_ERROR"),
onError: error => setRequestError(apiErrorCode(error) ?? ConnectionErrorCode.RequestFailed),
onSuccess: (data) => {
commitTbankConnectionBoundary(queryClient, data);
reset();
@@ -62,7 +64,7 @@ const TbankConnectionSectionLoaded: FC<TbankConnectionSectionLoadedProps> = (
},
},
);
const unavailableMessage = requestError === "TBANK_UNAVAILABLE" ? "tbank.unavailable" : "tbank.requestError";
const unavailableMessage = isApiErrorCode(requestError, ApiErrorCode.TbankUnavailable) ? "tbank.unavailable" : "tbank.requestError";
const isPending = update.isPending || remove.isPending;
const isConnected = status.connected;
useEffect(() => {
@@ -119,7 +121,7 @@ const TbankConnectionSectionLoaded: FC<TbankConnectionSectionLoadedProps> = (
{requestError && (
<Alert color="red">
{t(
requestError === "INVALID_TBANK_TOKEN"
isApiErrorCode(requestError, ApiErrorCode.InvalidTbankToken)
? "tbank.invalidToken"
: unavailableMessage,
)}