handle API errors
- created
handleAPIError
function - use
.then()
and.catch()
for brevity and easier understanding of what is being returned - stop using
// ts-expect-error
because in some cases it was hiding missing functions:
export const getOrders = createAsyncThunk<Paginated<Order>>(
"payments/getOrders",
async (_, { getState }) => {
try {
const {
payments: {
orders: { pagination, filters },
},
} = getState() as RootState;
const { data } = await api.get(`${url}/orders`, {
});
return data;
} catch (e) {
// @ts-expect-error
return rejectWithValue(e.response.data);
}
},
);
here, rejectWithValue
was not even being declared (line 3)