diff --git a/print/core/report.js b/print/core/report.js index c5182d1a8..d37b79c6d 100644 --- a/print/core/report.js +++ b/print/core/report.js @@ -23,39 +23,43 @@ class Report extends Component { } async toPdfStream() { - const template = await this.render(); - const defaultOptions = Object.assign({}, config.pdf); + try { + const template = await this.render(); + const defaultOptions = Object.assign({}, config.pdf); - const optionsPath = `${this.path}/options.json`; - const fullPath = path.resolve(__dirname, optionsPath); - let options = defaultOptions; - if (fs.existsSync(fullPath)) - options = require(optionsPath); + const optionsPath = `${this.path}/options.json`; + const fullPath = path.resolve(__dirname, optionsPath); + let options = defaultOptions; + if (fs.existsSync(fullPath)) + options = require(optionsPath); - return new Promise(resolve => { - Cluster.pool.queue({}, async({page}) => { - await page.emulateMediaType('screen'); - await page.setContent(template); + return new Promise(resolve => { + Cluster.pool.queue({}, async({page}) => { + await page.emulateMediaType('screen'); + await page.setContent(template); - const element = await page.$('#pageFooter'); + const element = await page.$('#pageFooter'); - let footer = '\n'; - if (element) { - footer = await page.evaluate(el => { - const html = el.innerHTML; - el.remove(); - return html; - }, element); - } + let footer = '\n'; + if (element) { + footer = await page.evaluate(el => { + const html = el.innerHTML; + el.remove(); + return html; + }, element); + } - options.headerTemplate = '\n'; - options.footerTemplate = footer; + options.headerTemplate = '\n'; + options.footerTemplate = footer; - const stream = await page.pdf(options); + const stream = await page.pdf(options); - resolve(stream); + resolve(stream); + }); }); - }); + } catch (e) { + console.log('ERROR CATCHED:', e); + } } /** diff --git a/print/templates/reports/claim-pickup-order/claim-pickup-order.js b/print/templates/reports/claim-pickup-order/claim-pickup-order.js index f7d21a2d3..2982379db 100755 --- a/print/templates/reports/claim-pickup-order/claim-pickup-order.js +++ b/print/templates/reports/claim-pickup-order/claim-pickup-order.js @@ -5,6 +5,8 @@ const reportFooter = new Component('report-footer'); module.exports = { name: 'claim-pickup-order', async serverPrefetch() { + // FORCE FAIL FOR TEST + throw new Error('Something went wrong'); this.client = await this.fetchClient(this.id); this.sales = await this.fetchSales(this.id); this.claimConfig = await this.fetchClaimConfig();