Skip to content

Commit

Permalink
introduce try catch again
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 committed Jan 27, 2021
1 parent 3834341 commit ac61dcf
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions x-pack/plugins/lens/server/usage/collectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,24 @@ function addEvents(prevEvents: Record<string, number>, newEvents: Record<string,
}

async function getLatestTaskState(taskManager: TaskManagerStartContract) {
const result = await taskManager.fetch({
query: { bool: { filter: { term: { _id: `task:Lens-lens_telemetry` } } } },
});
return result.docs;
try {
const result = await taskManager.fetch({
query: { bool: { filter: { term: { _id: `task:Lens-lens_telemetry` } } } },
});
return result.docs;
} catch (err) {
const errMessage = err && err.message ? err.message : err.toString();
/*
The usage service WILL to try to fetch from this collector before the task manager has been initialized, because the
task manager has to wait for all plugins to initialize first. It's fine to ignore it as next time around it will be
initialized (or it will throw a different type of error)
*/
if (!errMessage.includes('NotInitialized')) {
throw err;
}
}

return null;
}

function getDataByDate(dates: Record<string, Record<string, number>>) {
Expand Down

0 comments on commit ac61dcf

Please sign in to comment.