Skip to content

Commit

Permalink
fix(frontend): handle exceptions when generating the skills reports (…
Browse files Browse the repository at this point in the history
…PDF, DOCX)
  • Loading branch information
ApostolosBenisis committed Jan 24, 2025
1 parent 3a4ac07 commit 937bb2c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
24 changes: 14 additions & 10 deletions frontend-new/src/experiences/report/reportDocx/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ import { saveAs } from "src/experiences/saveAs";

export class DocxReportDownloadProvider implements IReportFormatProvider {
async download(props: ReportProps) {
const fileName = "compass-skills-report.docx";
const blob = await SkillReportDocx({
name: props.name,
email: props.email,
phone: props.phone,
address: props.address,
experiences: props.experiences,
conversationConductedAt: props.conversationConductedAt,
});
saveAs(blob, fileName);
try {
const fileName = "compass-skills-report.docx";
const blob = await SkillReportDocx({
name: props.name,
email: props.email,
phone: props.phone,
address: props.address,
experiences: props.experiences,
conversationConductedAt: props.conversationConductedAt,
});
saveAs(blob, fileName);
} catch (error) {
console.error("Failed to download report", error);
}
}
}
30 changes: 18 additions & 12 deletions frontend-new/src/experiences/report/reportPdf/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@ import { saveAs } from "src/experiences/saveAs";

export class PDFReportDownloadProvider implements IReportFormatProvider {
async download(props: ReportProps) {
const fileName = "compass-skills-report.pdf";
const blob = await pdf(
<SkillReportPDF
name={props.name}
email={props.email}
phone={props.phone}
address={props.address}
experiences={props.experiences}
conversationConductedAt={props.conversationConductedAt}
/>
).toBlob();
saveAs(blob, fileName);
try {
const fileName = "compass-skills-report.pdf";
const report = pdf(
<SkillReportPDF
name={props.name}
email={props.email}
phone={props.phone}
address={props.address}
experiences={props.experiences}
conversationConductedAt={props.conversationConductedAt}
/>,
);
// noinspection JSVoidFunctionReturnValueUsed Intellij is wrong here, this is a promise
const blob = await report.toBlob();
saveAs(blob, fileName);
} catch (error) {
console.error("Failed to download report", error);
}
}
}

0 comments on commit 937bb2c

Please sign in to comment.