process/elt: try/catch improvements
This commit is contained in:
parent
0390b976c2
commit
f4190a5bba
@ -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,
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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<ELT.ResponseEltOsago> {
|
||||
return await axios
|
||||
export async function getEltOsago(payload: ELT.RequestEltOsago, { signal }: QueryFunctionContext) {
|
||||
return axios
|
||||
.post<ELT.ResponseEltOsago>(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<ELT.ResponseEltKasko>(URL_ELT_KASKO, payload, { signal });
|
||||
|
||||
return data;
|
||||
return axios
|
||||
.post<ELT.ResponseEltKasko>(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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user