@shad0wz7/nestjs-pdf 3.0.1 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -0
- package/dist/index.cjs +282 -188
- package/dist/index.d.cts +71 -47
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +71 -47
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +273 -189
- package/dist/index.mjs.map +1 -1
- package/package.json +15 -14
package/README.md
CHANGED
|
@@ -208,6 +208,31 @@ these are the default extra arguments passed to Puppeteer:
|
|
|
208
208
|
|
|
209
209
|
You can use `forRootAsync(...)` if you need to provide configuration asynchronously.
|
|
210
210
|
|
|
211
|
+
## Error handling
|
|
212
|
+
|
|
213
|
+
All errors thrown by the library (missing template engine, template rendering failures, browser installation issues, PDF generation failures, signature placement issues, ...) are typed exceptions extending the abstract `NestjsPdfException` class, exported from the package root alongside a stable `NestjsPdfErrorCode` enum:
|
|
214
|
+
|
|
215
|
+
```typescript
|
|
216
|
+
import {
|
|
217
|
+
NestjsPdfException,
|
|
218
|
+
NestjsPdfErrorCode,
|
|
219
|
+
TemplateRenderException,
|
|
220
|
+
} from '@shad0wz7/nestjs-pdf';
|
|
221
|
+
|
|
222
|
+
try {
|
|
223
|
+
await pdfService.generatePdfFromTemplateHbsString(template, data);
|
|
224
|
+
} catch (error) {
|
|
225
|
+
if (error instanceof TemplateRenderException) {
|
|
226
|
+
logger.error(`${error.engine} rendering failed`, error.cause);
|
|
227
|
+
} else if (error instanceof NestjsPdfException) {
|
|
228
|
+
logger.error(error.code, error.message);
|
|
229
|
+
}
|
|
230
|
+
throw error;
|
|
231
|
+
}
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
See [docs/ERROR_HANDLING.md](docs/ERROR_HANDLING.md) for the full list of exceptions, their `code`, and an example NestJS exception filter.
|
|
235
|
+
|
|
211
236
|
## Examples
|
|
212
237
|
|
|
213
238
|
If you want to see a working example, check the `examples` folder and choose one of the subfolders with the engine you want to use.
|