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 {
} 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');
......
......@@ -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 }));
}
},
);
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