From 001eb4ee025ce37bf3028d0604ac3aaff36eddee Mon Sep 17 00:00:00 2001 From: nflnkr Date: Fri, 22 Mar 2024 13:27:15 +0300 Subject: [PATCH] fix promocode creation error display --- src/api/promocode/requests.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/api/promocode/requests.ts b/src/api/promocode/requests.ts index f28ee26..1e7e114 100644 --- a/src/api/promocode/requests.ts +++ b/src/api/promocode/requests.ts @@ -2,6 +2,7 @@ import { makeRequest } from "@frontend/kitui"; import { CreatePromocodeBody, GetPromocodeListBody, Promocode, PromocodeList } from "@root/model/promocodes"; import { parseAxiosError } from "@root/utils/parse-error"; +import { isAxiosError } from "axios"; const baseUrl = process.env.REACT_APP_DOMAIN + "/codeword/promocode"; @@ -38,6 +39,10 @@ const createPromocode = async (body: CreatePromocodeBody) => { return createPromocodeResponse; } catch (nativeError) { + if (isAxiosError(nativeError) && nativeError.response?.data.error === "Duplicate Codeword") { + throw new Error(`Промокод уже существует`); + } + const [error] = parseAxiosError(nativeError); throw new Error(`Ошибка создания промокода. ${error}`); }