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

return error using new interface

parent 9879fcf4
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"
...@@ -7,6 +7,7 @@ import { mockNetworkResponse } from '@/utils/mockNetworkResponse'; ...@@ -7,6 +7,7 @@ import { mockNetworkResponse } from '@/utils/mockNetworkResponse';
import { HttpStatusCode } from 'axios'; import { HttpStatusCode } from 'axios';
import { waitFor } from '@testing-library/react'; import { waitFor } from '@testing-library/react';
import { statisticsFixture } from '@/models/fixtures/statisticsFixture'; import { statisticsFixture } from '@/models/fixtures/statisticsFixture';
import { unwrapResult } from '@reduxjs/toolkit';
import { StatisticsState } from './statistics.types'; import { StatisticsState } from './statistics.types';
import statisticsReducer from './statistics.slice'; import statisticsReducer from './statistics.slice';
import { apiPath } from '../apiPath'; import { apiPath } from '../apiPath';
...@@ -56,11 +57,12 @@ describe('statistics reducer', () => { ...@@ -56,11 +57,12 @@ describe('statistics reducer', () => {
.onGet(apiPath.getStatisticsById(PROJECT_ID)) .onGet(apiPath.getStatisticsById(PROJECT_ID))
.reply(HttpStatusCode.NotFound, undefined); .reply(HttpStatusCode.NotFound, undefined);
const { type, payload } = await store.dispatch(getStatisticsById(PROJECT_ID)); const action = await store.dispatch(getStatisticsById(PROJECT_ID));
const { loading } = store.getState().statistics; const { loading } = store.getState().statistics;
expect(type).toBe('statistics/getStatisticsById/rejected'); expect(action.type).toBe('statistics/getStatisticsById/rejected');
expect(payload).toBe( expect(() => unwrapResult(action)).toThrow(
"Failed to fetch statistics: The page you're looking for doesn't exist. Please verify the URL and try again.", "Failed to fetch statistics: The page you're looking for doesn't exist. Please verify the URL and try again.",
); );
......
...@@ -3,14 +3,14 @@ import { Statistics } from '@/types/models'; ...@@ -3,14 +3,14 @@ import { Statistics } from '@/types/models';
import { validateDataUsingZodSchema } from '@/utils/validateDataUsingZodSchema'; import { validateDataUsingZodSchema } from '@/utils/validateDataUsingZodSchema';
import { createAsyncThunk } from '@reduxjs/toolkit'; import { createAsyncThunk } from '@reduxjs/toolkit';
import { statisticsSchema } from '@/models/statisticsSchema'; import { statisticsSchema } from '@/models/statisticsSchema';
import { getErrorMessage } from '@/utils/getErrorMessage';
import { ThunkConfig } from '@/types/store'; import { ThunkConfig } from '@/types/store';
import { getError } from '@/utils/error-report/getError';
import { apiPath } from '../apiPath'; import { apiPath } from '../apiPath';
import { STATISTICS_FETCHING_ERROR_PREFIX } from './statistics.constants'; import { STATISTICS_FETCHING_ERROR_PREFIX } from './statistics.constants';
export const getStatisticsById = createAsyncThunk<Statistics | undefined, string, ThunkConfig>( export const getStatisticsById = createAsyncThunk<Statistics | undefined, string, ThunkConfig>(
'statistics/getStatisticsById', 'statistics/getStatisticsById',
async (id, { rejectWithValue }) => { async id => {
try { try {
const response = await axiosInstance.get<Statistics>(apiPath.getStatisticsById(id)); const response = await axiosInstance.get<Statistics>(apiPath.getStatisticsById(id));
...@@ -18,8 +18,7 @@ export const getStatisticsById = createAsyncThunk<Statistics | undefined, string ...@@ -18,8 +18,7 @@ export const getStatisticsById = createAsyncThunk<Statistics | undefined, string
return isDataValid ? response.data : undefined; return isDataValid ? response.data : undefined;
} catch (error) { } catch (error) {
const errorMessage = getErrorMessage({ error, prefix: STATISTICS_FETCHING_ERROR_PREFIX }); return Promise.reject(getError({ error, prefix: STATISTICS_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