Skip to content

Commit

Permalink
feat: handle 404 response
Browse files Browse the repository at this point in the history
  • Loading branch information
simonadomnisoru committed Jan 19, 2024
1 parent 46f881c commit d22b48f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
4 changes: 2 additions & 2 deletions cypress/e2e/sharedSteps.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ Then(/^you see the opt in component for (.*)$/, (program) => {
});

And('the data store is clean', () => {
cy.buildApiUrl('dataStore', 'capture/useNewDashboard')
cy.buildApiUrl('dataStore/capture/useNewDashboard')
.then(dataStoreUrl =>
cy.request('PUT', dataStoreUrl, {}));
cy.request({ method: 'DELETE', url: dataStoreUrl, failOnStatusCode: false }));
});
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
// @flow
import { ofType } from 'redux-observable';
import { mergeMap, catchError } from 'rxjs/operators';
import { flatMap, catchError } from 'rxjs/operators';
import { EMPTY } from 'rxjs';
import { saveDataStore } from './DataStore.actions';
import { type UseNewDashboard } from './DataStore.types';
import { appStartActionTypes } from '../../../../components/AppStart';
import { programCollection } from '../../metaDataMemoryStores';

const setNewDashboardByDefault = (key: string, dataStoreValues) => {
if (!dataStoreValues) {
return {};
}
const programs = [...programCollection.keys()];
const valuesWithDefault = programs.reduce((acc, program) => {
const dataStoreValue = dataStoreValues[program];
acc[program] = dataStoreValue !== undefined ? dataStoreValue : true;
acc[program] = dataStoreValue === undefined ? true : dataStoreValue;
return acc;
}, {});

Expand All @@ -31,9 +34,15 @@ const getUserDataStoreFromApi = async querySingleResource =>
export const fetchDataStoreEpic = (action$: InputObservable, _: ReduxStore, { querySingleResource }: ApiUtils) =>
action$.pipe(
ofType(appStartActionTypes.APP_LOAD_SUCESS),
mergeMap(async () => {
const apiDataStore: UseNewDashboard = await getDataStoreFromApi(querySingleResource);
// $FlowFixMe
flatMap(async () => {
const apiDataStore: ?UseNewDashboard = await getDataStoreFromApi(querySingleResource)
.catch((error) => {
if (error.details.httpStatusCode === 404) {
return {};
}
return undefined;
});

return saveDataStore(setNewDashboardByDefault('dataStore', apiDataStore));
}),
catchError(() => EMPTY),
Expand All @@ -42,7 +51,7 @@ export const fetchDataStoreEpic = (action$: InputObservable, _: ReduxStore, { qu
export const fetchUserDataStoreEpic = (action$: InputObservable, _: ReduxStore, { querySingleResource }: ApiUtils) =>
action$.pipe(
ofType(appStartActionTypes.APP_LOAD_SUCESS),
mergeMap(async () => {
flatMap(async () => {
const apiUserDataStore: UseNewDashboard = await getUserDataStoreFromApi(querySingleResource);
// $FlowFixMe
return saveDataStore(setNewDashboardByDefault('userDataStore', apiUserDataStore));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export const useNewDashboardDesc = createReducerDescription({
[dataStoreActionTypes.SAVE_DATA_STORE]: (state, action) => {
const newState = { ...state };
const { dataStore, userDataStore } = action.payload;
dataStore && (newState.dataStore = dataStore);
userDataStore && (newState.userDataStore = userDataStore);
newState.dataStore = dataStore;
newState.userDataStore = userDataStore;

return newState;
},
Expand Down

0 comments on commit d22b48f

Please sign in to comment.