diff --git a/packages/api/src/elastic/highlights.ts b/packages/api/src/elastic/highlights.ts index 8277f7b9b..62902863b 100644 --- a/packages/api/src/elastic/highlights.ts +++ b/packages/api/src/elastic/highlights.ts @@ -289,13 +289,6 @@ export const updateHighlight = async ( return true } catch (e) { - if ( - e instanceof ResponseError && - e.message === 'document_missing_exception' - ) { - console.log('page has been deleted') - return false - } console.error('failed to update highlight in elastic', e) return false } diff --git a/packages/api/src/elastic/labels.ts b/packages/api/src/elastic/labels.ts index 69af5365e..90c930ac2 100644 --- a/packages/api/src/elastic/labels.ts +++ b/packages/api/src/elastic/labels.ts @@ -1,6 +1,7 @@ import { Label, PageContext } from './types' import { client, INDEX_ALIAS } from './index' import { EntityType } from '../datalayer/pubsub' +import { ResponseError } from '@elastic/elasticsearch/lib/errors' export const addLabelInPage = async ( pageId: string, @@ -38,6 +39,13 @@ export const addLabelInPage = async ( return true } catch (e) { + if ( + e instanceof ResponseError && + e.message === 'document_missing_exception' + ) { + console.log('page has been deleted', pageId) + return false + } console.error('failed to add a label in elastic', e) return false } @@ -74,6 +82,13 @@ export const updateLabelsInPage = async ( return true } catch (e) { + if ( + e instanceof ResponseError && + e.message === 'document_missing_exception' + ) { + console.log('page has been deleted', pageId) + return false + } console.error('failed to update labels in elastic', e) return false } diff --git a/packages/api/src/elastic/pages.ts b/packages/api/src/elastic/pages.ts index 5434dcfdf..f12d8da1d 100644 --- a/packages/api/src/elastic/pages.ts +++ b/packages/api/src/elastic/pages.ts @@ -21,6 +21,7 @@ import { } from '../utils/search' import { client, INDEX_ALIAS } from './index' import { EntityType } from '../datalayer/pubsub' +import { ResponseError } from '@elastic/elasticsearch/lib/errors' const appendQuery = (body: SearchBody, query: string): void => { body.query.bool.should.push({ @@ -237,6 +238,13 @@ export const updatePage = async ( return true } catch (e) { + if ( + e instanceof ResponseError && + e.message === 'document_missing_exception' + ) { + console.log('page has been deleted', id) + return false + } console.error('failed to update a page in elastic', e) return false } @@ -259,6 +267,13 @@ export const deletePage = async ( return true } catch (e) { + if ( + e instanceof ResponseError && + e.message === 'document_missing_exception' + ) { + console.log('page has been deleted', id) + return false + } console.error('failed to delete a page in elastic', e) return false } @@ -300,7 +315,7 @@ export const getPageByParam = async ( id: body.hits.hits[0]._id, } as Page } catch (e) { - console.error('failed to search pages in elastic', e) + console.error('failed to get pages by param in elastic', e) return undefined } } @@ -317,7 +332,11 @@ export const getPageById = async (id: string): Promise => { id: body._id as string, } as Page } catch (e) { - console.error('failed to search pages in elastic', e) + if (e instanceof ResponseError && e.statusCode === 404) { + console.log('page has been deleted', id) + return undefined + } + console.error('failed to get page by id in elastic', e) return undefined } }