Skip to content
Snippets Groups Projects
Commit 471c0e79 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

reject with error

parent 0117588e
No related branches found
No related tags found
2 merge requests!223reset the pin numbers before search results are fetch (so the results will be...,!199Resolve "[MIN-321] form for reporting errors in minerva"
...@@ -6,6 +6,7 @@ import { ...@@ -6,6 +6,7 @@ import {
} from '@/utils/createStoreInstanceUsingSliceReducer'; } from '@/utils/createStoreInstanceUsingSliceReducer';
import { mockNetworkResponse } from '@/utils/mockNetworkResponse'; import { mockNetworkResponse } from '@/utils/mockNetworkResponse';
import { HttpStatusCode } from 'axios'; import { HttpStatusCode } from 'axios';
import { unwrapResult } from '@reduxjs/toolkit';
import modelsReducer from './models.slice'; import modelsReducer from './models.slice';
import { getModels } from './models.thunks'; import { getModels } from './models.thunks';
import { ModelsState } from './models.types'; import { ModelsState } from './models.types';
...@@ -44,11 +45,11 @@ describe('models reducer', () => { ...@@ -44,11 +45,11 @@ describe('models reducer', () => {
it('should update store after failed getModels query', async () => { it('should update store after failed getModels query', async () => {
mockedAxiosClient.onGet(apiPath.getModelsString()).reply(HttpStatusCode.NotFound, []); 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; const { data, loading, error } = store.getState().models;
expect(type).toBe('project/getModels/rejected'); expect(action.type).toBe('project/getModels/rejected');
expect(payload).toBe( expect(() => unwrapResult(action)).toThrow(
"Failed to fetch models: The page you're looking for doesn't exist. Please verify the URL and try again.", "Failed to fetch models: The page you're looking for doesn't exist. Please verify the URL and try again.",
); );
expect(loading).toEqual('failed'); expect(loading).toEqual('failed');
......
...@@ -2,16 +2,16 @@ import { mapModelSchema } from '@/models/modelSchema'; ...@@ -2,16 +2,16 @@ import { mapModelSchema } from '@/models/modelSchema';
import { apiPath } from '@/redux/apiPath'; import { apiPath } from '@/redux/apiPath';
import { axiosInstance } from '@/services/api/utils/axiosInstance'; import { axiosInstance } from '@/services/api/utils/axiosInstance';
import { MapModel } from '@/types/models'; import { MapModel } from '@/types/models';
import { getErrorMessage } from '@/utils/getErrorMessage';
import { validateDataUsingZodSchema } from '@/utils/validateDataUsingZodSchema'; import { validateDataUsingZodSchema } from '@/utils/validateDataUsingZodSchema';
import { createAsyncThunk } from '@reduxjs/toolkit'; import { createAsyncThunk } from '@reduxjs/toolkit';
import { z } from 'zod'; import { z } from 'zod';
import { ThunkConfig } from '@/types/store'; import { ThunkConfig } from '@/types/store';
import { getError } from '@/utils/error-report/getError';
import { MODELS_FETCHING_ERROR_PREFIX } from './models.constants'; import { MODELS_FETCHING_ERROR_PREFIX } from './models.constants';
export const getModels = createAsyncThunk<MapModel[] | undefined, void, ThunkConfig>( export const getModels = createAsyncThunk<MapModel[] | undefined, void, ThunkConfig>(
'project/getModels', 'project/getModels',
async (_, { rejectWithValue }) => { async () => {
try { try {
const response = await axiosInstance.get<MapModel[]>(apiPath.getModelsString()); const response = await axiosInstance.get<MapModel[]>(apiPath.getModelsString());
...@@ -19,9 +19,7 @@ export const getModels = createAsyncThunk<MapModel[] | undefined, void, ThunkCon ...@@ -19,9 +19,7 @@ export const getModels = createAsyncThunk<MapModel[] | undefined, void, ThunkCon
return isDataValid ? response.data : undefined; return isDataValid ? response.data : undefined;
} catch (error) { } catch (error) {
const errorMessage = getErrorMessage({ error, prefix: MODELS_FETCHING_ERROR_PREFIX }); return Promise.reject(getError({ error, prefix: MODELS_FETCHING_ERROR_PREFIX }));
return rejectWithValue(errorMessage);
} }
}, },
); );
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment