diff --git a/x-pack/plugins/endpoint/public/embeddables/resolver/store/data/reducer.ts b/x-pack/plugins/endpoint/public/embeddables/resolver/store/data/reducer.ts index f2e4e930e09c0f..c06dc3291e4108 100644 --- a/x-pack/plugins/endpoint/public/embeddables/resolver/store/data/reducer.ts +++ b/x-pack/plugins/endpoint/public/embeddables/resolver/store/data/reducer.ts @@ -42,7 +42,7 @@ export const dataReducer: Reducer = (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; diff --git a/x-pack/plugins/endpoint/public/embeddables/resolver/store/data/selectors.ts b/x-pack/plugins/endpoint/public/embeddables/resolver/store/data/selectors.ts index dcf7e3e1334ea6..413f4db1cc99e0 100644 --- a/x-pack/plugins/endpoint/public/embeddables/resolver/store/data/selectors.ts +++ b/x-pack/plugins/endpoint/public/embeddables/resolver/store/data/selectors.ts @@ -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. diff --git a/x-pack/plugins/endpoint/public/embeddables/resolver/store/middleware.ts b/x-pack/plugins/endpoint/public/embeddables/resolver/store/middleware.ts index a42b43ef5c40b1..06758022b05c53 100644 --- a/x-pack/plugins/endpoint/public/embeddables/resolver/store/middleware.ts +++ b/x-pack/plugins/endpoint/public/embeddables/resolver/store/middleware.ts @@ -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. @@ -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]; } @@ -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], diff --git a/x-pack/plugins/endpoint/public/embeddables/resolver/types.ts b/x-pack/plugins/endpoint/public/embeddables/resolver/types.ts index 071c35ea064cfd..ec5ac188d7e6ee 100644 --- a/x-pack/plugins/endpoint/public/embeddables/resolver/types.ts +++ b/x-pack/plugins/endpoint/public/embeddables/resolver/types.ts @@ -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 @@ -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` diff --git a/x-pack/plugins/endpoint/public/embeddables/resolver/view/process_event_dot.tsx b/x-pack/plugins/endpoint/public/embeddables/resolver/view/process_event_dot.tsx index c2e7070fc77ca8..32928d511a1f90 100644 --- a/x-pack/plugins/endpoint/public/embeddables/resolver/view/process_event_dot.tsx +++ b/x-pack/plugins/endpoint/public/embeddables/resolver/view/process_event_dot.tsx @@ -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 []; } @@ -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; }