Skip to content

Commit

Permalink
Clean up cancel methods
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasolson committed Nov 7, 2023
1 parent 50eb538 commit b9fcdc3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,17 @@ export const eqlSearchStrategyProvider = (
);
};

const cancel = () => {
const cancel = async () => {
if (!id) return;
cancelAsyncSearch(id, esClient).catch((e) => {
try {
await cancelAsyncSearch(id, esClient);
} catch (e) {
// A 404 means either this search request does not exist, or that it is already cancelled
if (e.meta?.statusCode === 404) return;

// Log all other (unexpected) error messages
logger.error(`cancelEqlSearch error: ${e.message}`);
});
}
};

return pollSearch(search, cancel, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,17 @@ export const enhancedEsSearchStrategyProvider = (
);
};

const cancel = () => {
const cancel = async () => {
if (!id || options.isStored) return;
cancelAsyncSearch(id, esClient).catch((e) => {
try {
await cancelAsyncSearch(id, esClient);
} catch (e) {
// A 404 means either this search request does not exist, or that it is already cancelled
if (e.meta?.statusCode === 404) return;

// Log all other (unexpected) error messages
logger.error(`cancelAsyncSearch error: ${e.message}`);
});
}
};

return pollSearch(search, cancel, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,17 @@ export const sqlSearchStrategyProvider = (
);
};

const cancel = () => {
const cancel = async () => {
if (!id) return;
cancelAsyncSearch(id, esClient).catch((e) => {
try {
await cancelAsyncSearch(id, esClient);
} catch (e) {
// A 404 means either this search request does not exist, or that it is already cancelled
if (e.meta?.statusCode === 404) return;

// Log all other (unexpected) error messages
logger.error(`cancelSqlSearch error: ${e.message}`);
});
}
};

return pollSearch(search, cancel, {
Expand Down

0 comments on commit b9fcdc3

Please sign in to comment.