diff --git a/apps/web/Components/Calculation/Form/ELT/Kasko.tsx b/apps/web/Components/Calculation/Form/ELT/Kasko.tsx index e72d626..68c48b2 100644 --- a/apps/web/Components/Calculation/Form/ELT/Kasko.tsx +++ b/apps/web/Components/Calculation/Form/ELT/Kasko.tsx @@ -45,9 +45,31 @@ export const Kasko = observer(() => { queryFn: async (context: QueryFunctionContext) => { const payload = await makeEltKaskoRequest({ apolloClient, store }, row); const res = await getEltKasko(payload, context); - const companyRes = res[id]; - return { ...companyRes, id, key }; + if (res) { + const companyRes = res?.[id]; + + return { ...companyRes, id, key }; + } + + return { + error: null, + id, + kaskoSum: 0, + key, + message: null, + numCalc: 0, + paymentPeriods: [ + { + kaskoSum: 0, + }, + ], + requestId: '', + skCalcId: '', + status: null, + sum: 0, + totalFranchise: 0, + }; }, queryKey: ['elt', 'kasko', id], refetchOnWindowFocus: false, diff --git a/apps/web/Components/Calculation/Form/ELT/Osago.tsx b/apps/web/Components/Calculation/Form/ELT/Osago.tsx index ac6f0fe..941fbc7 100644 --- a/apps/web/Components/Calculation/Form/ELT/Osago.tsx +++ b/apps/web/Components/Calculation/Form/ELT/Osago.tsx @@ -35,9 +35,24 @@ export const Osago = observer(() => { queryFn: async (context: QueryFunctionContext) => { const payload = await makeEltOsagoRequest({ apolloClient, store }, row); const res = await getEltOsago(payload, context); - const companyRes = res[id]; - return { ...companyRes, id, key }; + if (res) { + const companyRes = res?.[id]; + + return { ...companyRes, id, key }; + } + + return { + error: null, + id, + key, + message: null, + numCalc: 0, + premiumSum: 0, + skCalcId: '', + status: null, + sum: 0, + }; }, queryKey: ['elt', 'osago', id], refetchOnWindowFocus: false, diff --git a/apps/web/api/elt/query.ts b/apps/web/api/elt/query.ts index 6aaacc8..2eef2bc 100644 --- a/apps/web/api/elt/query.ts +++ b/apps/web/api/elt/query.ts @@ -1,22 +1,31 @@ import type * as ELT from './types'; import getUrls from '@/config/urls'; import type { QueryFunctionContext } from '@tanstack/react-query'; +import type { AxiosError } from 'axios'; import axios from 'axios'; const { URL_ELT_KASKO, URL_ELT_OSAGO } = getUrls(); -export async function getEltOsago( - payload: ELT.RequestEltOsago, - { signal }: QueryFunctionContext -): Promise { - return await axios +export async function getEltOsago(payload: ELT.RequestEltOsago, { signal }: QueryFunctionContext) { + return axios .post(URL_ELT_OSAGO, payload, { signal }) .then((response) => response.data) - .catch((error) => error.response.data); + .catch((error: AxiosError | Error) => { + if (axios.isAxiosError(error)) { + // TODO: track error + throw new Error(error.message); + } + }); } export async function getEltKasko(payload: ELT.RequestEltKasko, { signal }: QueryFunctionContext) { - const { data } = await axios.post(URL_ELT_KASKO, payload, { signal }); - - return data; + return axios + .post(URL_ELT_KASKO, payload, { signal }) + .then((response) => response.data) + .catch((error: AxiosError | Error) => { + if (axios.isAxiosError(error)) { + // TODO: track error + throw new Error(error.message); + } + }); }