diff --git a/src/redux/models/models.reducers.test.ts b/src/redux/models/models.reducers.test.ts index fc6e0af1e28e47a3bb0e2ed3a38186549c053907..c25cd72d4bff9e4510cbb0b6b596201c13831ec1 100644 --- a/src/redux/models/models.reducers.test.ts +++ b/src/redux/models/models.reducers.test.ts @@ -6,6 +6,7 @@ import { } from '@/utils/createStoreInstanceUsingSliceReducer'; import { mockNetworkResponse } from '@/utils/mockNetworkResponse'; import { HttpStatusCode } from 'axios'; +import { unwrapResult } from '@reduxjs/toolkit'; import modelsReducer from './models.slice'; import { getModels } from './models.thunks'; import { ModelsState } from './models.types'; @@ -44,11 +45,11 @@ describe('models reducer', () => { it('should update store after failed getModels query', async () => { mockedAxiosClient.onGet(apiPath.getModelsString()).reply(HttpStatusCode.NotFound, []); - const { type, payload } = await store.dispatch(getModels()); + const action = await store.dispatch(getModels()); const { data, loading, error } = store.getState().models; - expect(type).toBe('project/getModels/rejected'); - expect(payload).toBe( + expect(action.type).toBe('project/getModels/rejected'); + expect(() => unwrapResult(action)).toThrow( "Failed to fetch models: The page you're looking for doesn't exist. Please verify the URL and try again.", ); expect(loading).toEqual('failed'); diff --git a/src/redux/models/models.thunks.ts b/src/redux/models/models.thunks.ts index 2e0fd68d89e09cff7b66e6c5e1aefff3acc15486..d81096c9dd853bf571c31de25006583c1b60c36a 100644 --- a/src/redux/models/models.thunks.ts +++ b/src/redux/models/models.thunks.ts @@ -2,16 +2,16 @@ import { mapModelSchema } from '@/models/modelSchema'; import { apiPath } from '@/redux/apiPath'; import { axiosInstance } from '@/services/api/utils/axiosInstance'; import { MapModel } from '@/types/models'; -import { getErrorMessage } from '@/utils/getErrorMessage'; import { validateDataUsingZodSchema } from '@/utils/validateDataUsingZodSchema'; import { createAsyncThunk } from '@reduxjs/toolkit'; import { z } from 'zod'; import { ThunkConfig } from '@/types/store'; +import { getError } from '@/utils/error-report/getError'; import { MODELS_FETCHING_ERROR_PREFIX } from './models.constants'; export const getModels = createAsyncThunk<MapModel[] | undefined, void, ThunkConfig>( 'project/getModels', - async (_, { rejectWithValue }) => { + async () => { try { const response = await axiosInstance.get<MapModel[]>(apiPath.getModelsString()); @@ -19,9 +19,7 @@ export const getModels = createAsyncThunk<MapModel[] | undefined, void, ThunkCon return isDataValid ? response.data : undefined; } catch (error) { - const errorMessage = getErrorMessage({ error, prefix: MODELS_FETCHING_ERROR_PREFIX }); - - return rejectWithValue(errorMessage); + return Promise.reject(getError({ error, prefix: MODELS_FETCHING_ERROR_PREFIX })); } }, );