Skip to content

Commit

Permalink
chore(lib): add 404 handling back to getItem (#1040)
Browse files Browse the repository at this point in the history
* add 404 handling back

* fix eslint
  • Loading branch information
tiffanyvu authored Jan 17, 2025
1 parent ac1d50f commit 8181a1c
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions lib/libs/opensearch-lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,24 @@ export async function getItem(
index: opensearch.Index,
id: string,
): Promise<ItemResult | undefined> {
client = client || (await getClient(host));
const response = await client.get({ id, index });
const item = decodeUtf8(response).body;
if (item.found === false || !item._source) {
return undefined;
try {
client = client || (await getClient(host));
const response = await client.get({ id, index });
const item = decodeUtf8(response).body;
if (item.found === false || !item._source) {
return undefined;
}
return item;
} catch (error) {
if (
(error instanceof OpensearchErrors.ResponseError && error.statusCode === 404) ||
error.meta?.statusCode === 404
) {
console.log("Error (404) retrieving in OpenSearch:", error);
return undefined;
}
throw error;
}
return item;
}

export async function getItems(ids: string[]): Promise<OSDocument[]> {
Expand Down

0 comments on commit 8181a1c

Please sign in to comment.