fix promocode creation error display
This commit is contained in:
parent
9933f7cfbd
commit
001eb4ee02
@ -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}`);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user