Skip to content

handle API errors

Fabio Maschi requested to merge fix/handle-api-errors into main
  • 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)

Merge request reports

Loading