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

reject redux with error

parent 662c1e39
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"
......@@ -14,6 +14,7 @@ import {
import { mockNetworkResponse } from '@/utils/mockNetworkResponse';
import { HttpStatusCode } from 'axios';
import { waitFor } from '@testing-library/react';
import { unwrapResult } from '@reduxjs/toolkit';
import { apiPath } from '../apiPath';
import overlaysReducer from './overlays.slice';
import {
......@@ -80,11 +81,11 @@ describe('overlays reducer', () => {
.onGet(apiPath.getAllOverlaysByProjectIdQuery(PROJECT_ID, { publicOverlay: true }))
.reply(HttpStatusCode.NotFound, []);
const { type, payload } = await store.dispatch(getAllPublicOverlaysByProjectId(PROJECT_ID));
const action = await store.dispatch(getAllPublicOverlaysByProjectId(PROJECT_ID));
const { data, loading, error } = store.getState().overlays;
expect(type).toBe('overlays/getAllPublicOverlaysByProjectId/rejected');
expect(payload).toBe(
expect(action.type).toBe('overlays/getAllPublicOverlaysByProjectId/rejected');
expect(() => unwrapResult(action)).toThrow(
"Failed to fetch overlays: The page you're looking for doesn't exist. Please verify the URL and try again.",
);
expect(loading).toEqual('failed');
......
......@@ -15,6 +15,7 @@ import { showToast } from '@/utils/showToast';
import { getErrorMessage } from '@/utils/getErrorMessage';
import { ThunkConfig } from '@/types/store';
import { BASE_API_URL } from '@/constants';
import { getError } from '@/utils/error-report/getError';
import { apiPath } from '../apiPath';
import {
CHUNK_SIZE,
......@@ -32,7 +33,7 @@ import type { RootState } from '../store';
export const getAllPublicOverlaysByProjectId = createAsyncThunk<MapOverlay[], string, ThunkConfig>(
'overlays/getAllPublicOverlaysByProjectId',
async (projectId: string, { rejectWithValue }) => {
async (projectId: string) => {
try {
const response = await axiosInstance.get<MapOverlay[]>(
apiPath.getAllOverlaysByProjectIdQuery(projectId, { publicOverlay: true }),
......@@ -42,9 +43,7 @@ export const getAllPublicOverlaysByProjectId = createAsyncThunk<MapOverlay[], st
return isDataValid ? response.data : [];
} catch (error) {
const errorMessage = getErrorMessage({ error, prefix: OVERLAYS_FETCHING_ERROR_PREFIX });
return rejectWithValue(errorMessage);
return Promise.reject(getError({ error, prefix: OVERLAYS_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