From 8de8b8b65b3c750dd1b4cd2bd60d6fb28c165e95 Mon Sep 17 00:00:00 2001 From: matthew Date: Sun, 9 Oct 2022 13:30:37 +0400 Subject: [PATCH] add try catch html to text --- .../services/modules/parser/helpers.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/searching-front/services/modules/parser/helpers.ts b/searching-front/services/modules/parser/helpers.ts index bc86024..338acba 100644 --- a/searching-front/services/modules/parser/helpers.ts +++ b/searching-front/services/modules/parser/helpers.ts @@ -12,12 +12,16 @@ const convert = (html: string) => listStyle: "linebreak", }) export const htmlToText = (html: string) => { - const text = convert(html) - - return text - .replaceAll(/&\w*;/g, "") - .replaceAll(//g, "") - .replaceAll(/<.*><\/.*>/g, "") + try { + const text = convert(html) + return text + .replaceAll(/&\w*;/g, "") + .replaceAll(//g, "") + .replaceAll(/<.*><\/.*>/g, "") + } catch (e) { + console.log("htmlToText", e) + return "" + } } export const SHOULD_NOT_PARSE = "SHOULD_NOT_PARSE"