Skip to content

Commit 7f55ec4

Browse files
changes
1 parent 3d627ee commit 7f55ec4

File tree

1 file changed

+45
-7
lines changed
  • packages/compass-global-writes/src/store

1 file changed

+45
-7
lines changed

packages/compass-global-writes/src/store/reducer.ts

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
showConfirmation as showConfirmationModal,
66
} from '@mongodb-js/compass-components';
77
import type { ManagedNamespace } from '../services/atlas-global-writes-service';
8+
import { GlobalWrites } from '../components';
89

910
export const POLLING_INTERVAL = 5000;
1011

@@ -30,6 +31,7 @@ enum GlobalWritesActionTypes {
3031
NamespaceShardKeyFetched = 'global-writes/NamespaceShardKeyFetched',
3132

3233
ShardZonesFetched = 'global-writes/ShardZonesFetched',
34+
ShardZonesFetchedError = 'global-writes/ShardZonesFetchedError',
3335

3436
SubmittingForShardingStarted = 'global-writes/SubmittingForShardingStarted',
3537
SubmittingForShardingFinished = 'global-writes/SubmittingForShardingFinished',
@@ -67,6 +69,10 @@ type ShardZonesFetchedAction = {
6769
shardZones: ShardZoneData[];
6870
};
6971

72+
type ShardZonesFetchedErrorAction = {
73+
type: GlobalWritesActionTypes.ShardZonesFetchedError;
74+
};
75+
7076
type SubmittingForShardingStartedAction = {
7177
type: GlobalWritesActionTypes.SubmittingForShardingStarted;
7278
};
@@ -320,6 +326,18 @@ const reducer: Reducer<RootState, Action> = (state = initialState, action) => {
320326
};
321327
}
322328

329+
if (
330+
isAction<ShardZonesFetchedErrorAction>(
331+
action,
332+
GlobalWritesActionTypes.ShardZonesFetchedError
333+
)
334+
) {
335+
return {
336+
...state,
337+
shardZones: [],
338+
};
339+
}
340+
323341
if (
324342
isAction<SubmittingForShardingStartedAction>(
325343
action,
@@ -773,18 +791,38 @@ export const fetchNamespaceShardKey = (): GlobalWritesThunkAction<
773791

774792
export const fetchShardingZones = (): GlobalWritesThunkAction<
775793
Promise<void>,
776-
ShardZonesFetchedAction
794+
ShardZonesFetchedAction | ShardZonesFetchedErrorAction
777795
> => {
778-
return async (dispatch, getState, { atlasGlobalWritesService }) => {
796+
return async (
797+
dispatch,
798+
getState,
799+
{ atlasGlobalWritesService, connectionInfoRef }
800+
) => {
779801
const { shardZones } = getState();
780802
if (shardZones.length > 0) {
781803
return;
782804
}
783-
const shardingZones = await atlasGlobalWritesService.getShardingZones();
784-
dispatch({
785-
type: GlobalWritesActionTypes.ShardZonesFetched,
786-
shardZones: shardingZones,
787-
});
805+
try {
806+
throw new Error('dan echlin fake error');
807+
const shardingZones = await atlasGlobalWritesService.getShardingZones();
808+
dispatch({
809+
type: GlobalWritesActionTypes.ShardZonesFetched,
810+
shardZones: shardingZones,
811+
});
812+
} catch (error) {
813+
dispatch({
814+
type: GlobalWritesActionTypes.ShardZonesFetchedError,
815+
});
816+
openToast(
817+
`global-writes-fetch-sharding-zones-error-${connectionInfoRef.current.id}`,
818+
{
819+
title: `Failed to fetch sharding zones: ${(error as Error).message}`,
820+
dismissible: true,
821+
timeout: 5000,
822+
variant: 'important',
823+
}
824+
);
825+
}
788826
};
789827
};
790828

0 commit comments

Comments
 (0)