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.

46 lines (43 loc) 1.68 kB
import { ErrorHandler } from '../../../utils/ErrorHandler/ErrorHandler.js'; import { cancelRequest } from './utils.js'; import { captureDprError } from '../../../utils/captureError.js'; class RequestReportController { layoutPath; services; constructor(layoutPath, services) { this.layoutPath = layoutPath; this.services = services; } errorHandler = async (error, req, res, _next) => { 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 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(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')); }; } export { RequestReportController, RequestReportController as default }; //# sourceMappingURL=controller.js.map