@nestjsforge/pdfme

Error Handling

Handle typed exceptions thrown by PdfmeService.

@nestjsforge/pdfme throws typed exception classes so you can catch specific failure scenarios:

import {
  PdfmeException,
  PdfmeGenerationException,
  PdfmeValidationException,
  PdfmeFontException,
  PdfmePluginException,
} from '@nestjsforge/pdfme';

try {
  const pdf = await this.pdfme.generate({ template, inputs });
} catch (err) {
  if (err instanceof PdfmeValidationException) {
    throw new BadRequestException(err.errors);
  }
  if (err instanceof PdfmeFontException) {
    throw new InternalServerErrorException('Font not found');
  }
  if (err instanceof PdfmeGenerationException) {
    this.logger.error('PDF generation failed', err.stack);
    throw new InternalServerErrorException('PDF generation failed');
  }
  throw err;
}

Exception hierarchy

ClassExtendsDescription
PdfmeExceptionErrorBase exception for all pdfme errors
PdfmeGenerationExceptionPdfmeExceptionPDF generation failed
PdfmeValidationExceptionPdfmeExceptionTemplate or input validation failed
PdfmeFontExceptionPdfmeExceptionFont file not found or invalid
PdfmePluginExceptionPdfmeExceptionPlugin execution failed
PdfmeConfigExceptionPdfmeExceptionModule configuration error