From 2b557d93ebc47f4d1d8d86644fd313e484cb9adf Mon Sep 17 00:00:00 2001 From: ainouzgali Date: Wed, 8 May 2024 19:28:52 +0300 Subject: [PATCH] feat: use type guard for error --- .../compile-template/compile-template.usecase.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/application-generic/src/usecases/compile-template/compile-template.usecase.ts b/packages/application-generic/src/usecases/compile-template/compile-template.usecase.ts index 31707e10b7d..bc4370c0812 100644 --- a/packages/application-generic/src/usecases/compile-template/compile-template.usecase.ts +++ b/packages/application-generic/src/usecases/compile-template/compile-template.usecase.ts @@ -1,7 +1,7 @@ import { Injectable } from '@nestjs/common'; import * as Handlebars from 'handlebars'; import { format } from 'date-fns'; -import { HandlebarHelpersEnum } from '@novu/shared'; +import { checkIsResponseError, HandlebarHelpersEnum } from '@novu/shared'; import { CompileTemplateCommand } from './compile-template.command'; import * as i18next from 'i18next'; @@ -214,10 +214,12 @@ export class CompileTemplate { const template = Handlebars.compile(templateContent); result = template(command.data, {}); - } catch (e: any) { - throw new ApiException( - e?.message || `Message content could not be generated` - ); + } catch (e: unknown) { + let errorMessage = `Message content could not be generated`; + if (checkIsResponseError(e)) { + errorMessage = e.message; + } + throw new ApiException(errorMessage); } return result.replace(/'/g, "'");