Skip to content

Commit 427f562

Browse files
committed
Preventing from filaing entire publishing when referenced font can not be found.
1 parent 4abe38d commit 427f562

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/components/custom-html/ko/customHtmlPublishViewModelBinder.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { JssCompiler } from "@paperbits/styles/jssCompiler";
88
import { Logger } from "@paperbits/common/logging/logger";
99
import { WellKnownEventTypes } from "../../../logging/wellKnownEventTypes";
1010

11-
export class CustomHtmlPublishViewModelBinder implements ViewModelBinder<CustomHtmlModel, CustomHtmlViewModel> {
11+
export class CustomHtmlPublishViewModelBinder implements ViewModelBinder<CustomHtmlModel, CustomHtmlViewModel> {
1212
constructor(
1313
private readonly styleCompiler: StyleCompiler,
1414
private readonly blobStorage: IBlobStorage,
@@ -58,22 +58,31 @@ export class CustomHtmlPublishViewModelBinder implements ViewModelBinder<CustomH
5858
private async getCustomFonts(): Promise<string> {
5959
const globalStyleSheet = await this.styleCompiler.getStyleSheet();
6060
const styleSheet = new StyleSheet();
61+
6162
if (globalStyleSheet.fontFaces.length > 0) {
6263
for (let i = 0; i < globalStyleSheet.fontFaces.length; i++) {
6364
const fontFace = globalStyleSheet.fontFaces[i];
65+
6466
if (fontFace.source?.startsWith("/fonts/")) {
65-
const fontData = await this.blobStorage.downloadBlob(fontFace.source);
66-
this.logger.trackEvent(WellKnownEventTypes.Publishing, { message: `CustomHtmlPublish: Adding ${fontFace.source} font as base64` });
67-
const fontDataString = Buffer.from(fontData).toString("base64");
68-
fontFace.source = `data:font/truetype;charset=utf-8;base64,${fontDataString}`
69-
styleSheet.fontFaces.push(fontFace);
67+
try {
68+
const fontData = await this.blobStorage.downloadBlob(fontFace.source);
69+
this.logger.trackEvent(WellKnownEventTypes.Publishing, { message: `CustomHtmlPublish: Adding ${fontFace.source} font as base64` });
70+
const fontDataString = Buffer.from(fontData).toString("base64");
71+
fontFace.source = `data:font/truetype;charset=utf-8;base64,${fontDataString}`
72+
styleSheet.fontFaces.push(fontFace);
73+
}
74+
catch (error) {
75+
this.logger.trackError(error, { message: `Unable to add the font ${fontFace.source} to Custom HTML widget stylesheet.` });
76+
}
7077
}
7178
}
7279
}
80+
7381
if (styleSheet.fontFaces.length > 0) {
7482
const compiler = new JssCompiler();
7583
return compiler.compile(styleSheet);
7684
}
85+
7786
return "";
7887
}
7988
}

0 commit comments

Comments
 (0)