Skip to content

Commit

Permalink
feat: use type guard for error
Browse files Browse the repository at this point in the history
  • Loading branch information
ainouzgali committed May 8, 2024
1 parent aa774a2 commit 2b557d9
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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, "'");
Expand Down

0 comments on commit 2b557d9

Please sign in to comment.