Skip to content

Commit

Permalink
R Austin review: Remove Error construction
Browse files Browse the repository at this point in the history
  • Loading branch information
Brent Kimmel committed May 18, 2020
1 parent 7750c97 commit 9e07c11
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const dataReducer: Reducer<DataState, ResolverAction> = (state = initialS
if (statsMap) {
const currentStatsMap = new Map(statsMap);
const resolverEvent = action.payload;
currentStatsMap.set(resolverEvent, new Error('error requesting related events'));
currentStatsMap.set(resolverEvent, 'error');
return { ...state, resultsEnrichedWithRelatedEventInfo: currentStatsMap };
}
return state;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,13 +432,12 @@ export const relatedEventStats = createSelector(relatedEventResults, function ge

for (const updatedEvent of relatedEventResults.keys()) {
const newStatsEntry = relatedEventResults.get(updatedEvent);
if (newStatsEntry === 'error') {
// If the entry is an error, return it as is
relatedEventStats.set(updatedEvent, newStatsEntry);
continue;
}
if (typeof newStatsEntry === 'object') {
// compile stats
if (newStatsEntry instanceof Error) {
// If the entry is an error, return it as is
relatedEventStats.set(updatedEvent, newStatsEntry);
continue;
}
/**
* Otherwise, it should be a valid stats entry.
* Do the work to compile the stats.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function flattenEvents(children: ResolverNode[], events: ResolverEvent[] = []):
}, events);
}

type RelatedEventAPIResponse = Error | { events: ResolverEvent[] };
type RelatedEventAPIResponse = 'error' | { events: ResolverEvent[] };
/**
* As the design goal of this stopgap was to prevent saturating the server with /events
* requests, this generator intentionally processes events in serial rather than in parallel.
Expand All @@ -52,7 +52,7 @@ async function* getEachRelatedEventsResult(
query: { events: 100 },
});
} catch (e) {
result = new Error(`Error fetching related events for entity=${id}`);
result = 'error';
}
yield [eventToQueryForRelateds, result];
}
Expand Down Expand Up @@ -119,7 +119,7 @@ export const resolverMiddlewareFactory: MiddlewareFactory = context => {
* [event requested , response of event against the /related api]
*/
const [baseEvent, apiResults] = results;
if (apiResults instanceof Error) {
if (apiResults === 'error') {
api.dispatch({
type: 'serverFailedToReturnRelatedEventData',
payload: results[0],
Expand Down
7 changes: 5 additions & 2 deletions x-pack/plugins/endpoint/public/embeddables/resolver/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ export interface RelatedEventDataEntry {
* Represents the status of the request for related event data, which will be either the data,
* a value indicating that it's still waiting for the data or an Error indicating the data can't be retrieved as expected
*/
export type RelatedEventDataResults = RelatedEventDataEntry | 'waitingForRelatedEventData' | Error;
export type RelatedEventDataResults =
| RelatedEventDataEntry
| 'waitingForRelatedEventData'
| 'error';

/**
* This represents the raw related events data enhanced with statistics
Expand All @@ -166,7 +169,7 @@ export type RelatedEventDataEntryWithStats = RelatedEventDataEntry & {
export type RelatedEventEntryWithStatsOrWaiting =
| RelatedEventDataEntryWithStats
| `waitingForRelatedEventData`
| Error;
| 'error';

/**
* This represents a Map that will return either a `RelatedEventDataEntryWithStats`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ export const ProcessEventDot = styled(
* e.g. "10 DNS", "230 File"
*/
const relatedEventOptions = useMemo(() => {
if (relatedEvents instanceof Error) {
if (relatedEvents === 'error') {
// Return an empty set of options if there was an error requesting them
return [];
}
Expand Down Expand Up @@ -377,7 +377,7 @@ export const ProcessEventDot = styled(
// If related events have not yet been requested
return subMenuAssets.initialMenuStatus;
}
if (relatedEvents instanceof Error) {
if (relatedEvents === 'error') {
// If there was an error when we tried to request the events
return subMenuAssets.menuError;
}
Expand Down

0 comments on commit 9e07c11

Please sign in to comment.