Skip to content

Commit

Permalink
Add error handling action
Browse files Browse the repository at this point in the history
  • Loading branch information
kqualters-elastic committed Oct 5, 2020
1 parent 2545069 commit 532332d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ interface AppRequestedAdditionalRelatedEvents {
readonly payload: {};
}

interface ServerFailedToReturnNodeEventsInCategory {
readonly type: 'serverFailedToReturnNodeEventsInCategory';
}

/**
* When an additional page of related events is returned
*/
Expand Down Expand Up @@ -138,4 +142,5 @@ export type DataAction =
| AppRequestedAdditionalRelatedEvents
| ServerFailedToReturnAdditionalRelatedEventData
| ServerReturnedAdditionalRelatedEventData
| ServerFailedToReturnNodeEventsInCategory
| AppAbortedResolverDataRequest;
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const initialState: DataState = {
relatedEvents: new Map(),
resolverComponentInstanceID: undefined,
};

/* eslint-disable complexity */
export const dataReducer: Reducer<DataState, ResolverAction> = (state = initialState, action) => {
if (action.type === 'appReceivedNewExternalProperties') {
const nextState: DataState = {
Expand Down Expand Up @@ -167,6 +167,10 @@ export const dataReducer: Reducer<DataState, ResolverAction> = (state = initialS
const nextState: DataState = {
...state,
nodeEventsInCategory: {
nodeID: '',
eventCategory: '',
events: [],
cursor: null,
...state.nodeEventsInCategory,
loading: true,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,20 @@ export function RelatedEventsFetcher(
});
const { nodeID, eventCategory, cursor } = nodeEventsInCategory;
let result: ResolverPaginatedEvents | null = null;
if (cursor) {
result = await dataAccessLayer.eventsWithEntityIDAndCategory(
nodeID,
eventCategory,
cursor
);
} else {
result = await dataAccessLayer.eventsWithEntityIDAndCategory(nodeID, eventCategory);
try {
if (cursor) {
result = await dataAccessLayer.eventsWithEntityIDAndCategory(
nodeID,
eventCategory,
cursor
);
} else {
result = await dataAccessLayer.eventsWithEntityIDAndCategory(nodeID, eventCategory);
}
} catch (error) {
api.dispatch({
type: 'serverFailedToReturnNodeEventsInCategory',
});
}

if (result) {
Expand Down

0 comments on commit 532332d

Please sign in to comment.