@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
| Class | Extends | Description |
|---|---|---|
| PdfmeException | Error | Base exception for all pdfme errors |
| PdfmeGenerationException | PdfmeException | PDF generation failed |
| PdfmeValidationException | PdfmeException | Template or input validation failed |
| PdfmeFontException | PdfmeException | Font file not found or invalid |
| PdfmePluginException | PdfmeException | Plugin execution failed |
| PdfmeConfigException | PdfmeException | Module configuration error |