'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var node = require('@sentry/node');
var ErrorHandler = require('../../../utils/ErrorHandler/ErrorHandler.js');
var utils = require('./utils.js');

class RequestReportController {
    layoutPath;
    services;
    constructor(layoutPath, services) {
        this.layoutPath = layoutPath;
        this.services = services;
    }
    errorHandler = async (error, req, res, _next) => {
        node.captureException(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
