Skip to content

Commit

Permalink
feat: catch errors of wrong use of handlebars
Browse files Browse the repository at this point in the history
  • Loading branch information
ainouzgali committed May 8, 2024
1 parent 68e04bb commit aa774a2
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { HandlebarHelpersEnum } from '@novu/shared';

import { CompileTemplateCommand } from './compile-template.command';
import * as i18next from 'i18next';
import { ApiException } from '../../utils/exceptions';

const assertResult = (condition: boolean, options) => {
const fn = condition ? options.fn : options.inverse;
Expand Down Expand Up @@ -208,10 +209,16 @@ Handlebars.registerHelper(
export class CompileTemplate {
async execute(command: CompileTemplateCommand): Promise<string> {
const templateContent = command.template;

const template = Handlebars.compile(templateContent);

const result = template(command.data, {});
let result = '';
try {
const template = Handlebars.compile(templateContent);

result = template(command.data, {});
} catch (e: any) {
throw new ApiException(
e?.message || `Message content could not be generated`
);
}

return result.replace(/&#x27;/g, "'");
}
Expand Down

0 comments on commit aa774a2

Please sign in to comment.