From fd18affaec243ce1cbd130e46fe58b1991d1e2b1 Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Mon, 28 Mar 2022 21:16:33 +0800 Subject: [PATCH] fix document_missing_exception being thrown to sentry when updating page in elastic --- packages/api/src/elastic/index.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/api/src/elastic/index.ts b/packages/api/src/elastic/index.ts index 4165e687b..7a41b0463 100644 --- a/packages/api/src/elastic/index.ts +++ b/packages/api/src/elastic/index.ts @@ -25,6 +25,7 @@ import { } from './types' import { readFileSync } from 'fs' import { join } from 'path' +import { ResponseError } from '@elastic/elasticsearch/lib/errors' const INDEX_NAME = 'pages' const INDEX_ALIAS = 'pages_alias' @@ -210,6 +211,13 @@ export const updatePage = async ( return true } catch (e) { + if ( + e instanceof ResponseError && + e.message === 'document_missing_exception' + ) { + console.info('page has been deleted', id) + return false + } console.error('failed to update a page in elastic', e) return false }