UNPKG

@ministryofjustice/hmpps-digital-prison-reporting-frontend

Version:

The Digital Prison Reporting Frontend contains templates and code to help display data effectively in UI applications.

51 lines (46 loc) 1.8 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var ErrorHandler = require('../../../utils/ErrorHandler/ErrorHandler.js'); var utils = require('./utils.js'); var captureError = require('../../../utils/captureError.js'); class RequestReportController { layoutPath; services; constructor(layoutPath, services) { this.layoutPath = layoutPath; this.services = services; } errorHandler = async (error, req, res, _next) => { captureError.captureDprError(error); res.render(`dpr/routes/journeys/view-report/error`, { layoutPath: this.layoutPath, ...(req.body && { ...req.body }), ...req.params, error: req.body?.error, params: req?.params, }); }; CANCEL = async (req, res, _next) => { try { await utils.cancelRequest({ req, res, services: this.services, }); } catch (error) { req.body ??= {}; req.body.title = 'Failed to abort request'; req.body.errorDescription = 'We were unable to abort the report request for the following reason:'; req.body.error = new ErrorHandler.ErrorHandler(error).formatError(); req.flash('ERROR_BODY', JSON.stringify(req.body)); req.flash('ERROR_PARAMS', JSON.stringify(req.params)); req.flash('ERROR', JSON.stringify(req.body?.error || {})); return res.redirect(`${req.originalUrl}/failed`); } return res.redirect(req.originalUrl.replace('/cancel', '/status')); }; } exports.RequestReportController = RequestReportController; exports.default = RequestReportController; //# sourceMappingURL=controller.js.map