Skip to content

Commit

Permalink
Move dispatch call out of HTTP try-catch
Browse files Browse the repository at this point in the history
We use try...catch for HTTP control flow logic. We don't want to treat
runtime errors the same as HTTP errors though. Move `dispatch` call
out of that try catch.
  • Loading branch information
oatkiller committed Jun 30, 2020
1 parent f4a26da commit 54043fd
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,26 @@ export const resolverMiddlewareFactory: MiddlewareFactory = (context) => {
action.type === 'appDetectedMissingEventData'
) {
const entityIdToFetchFor = action.payload;
let result: ResolverRelatedEvents;
let result: ResolverRelatedEvents | undefined;
try {
result = await context.services.http.get(
`/api/endpoint/resolver/${entityIdToFetchFor}/events`,
{
query: { events: 100 },
}
);
} catch {
api.dispatch({
type: 'serverFailedToReturnRelatedEventData',
payload: action.payload,
});
}

if (result) {
api.dispatch({
type: 'serverReturnedRelatedEventData',
payload: result,
});
} catch (e) {
api.dispatch({
type: 'serverFailedToReturnRelatedEventData',
payload: action.payload,
});
}
}
};
Expand Down

0 comments on commit 54043fd

Please sign in to comment.