'use strict';

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

var express = require('express');
var node = require('@sentry/node');
var logger = require('../utils/logger.js');
var routes$1 = require('./journeys/routes.js');
var setUpNestedRoute = require('../middleware/setUpNestedRoute.js');

const errorRequestHandler = (layoutPath) => (error, _req, res, next) => {
    if (error.status === 401 || error.status === 403) {
        return res.render('dpr/routes/authError.njk', {
            layoutPath,
            message: 'Sorry, there is a problem with authenticating your request',
        });
    }
    node.captureException(error);
    if (error.status >= 400) {
        return res.render('dpr/routes/serviceProblem.njk', {
            layoutPath,
        });
    }
    return next(error);
};
function routes(routeImportParams) {
    logger.default.info('Initialiasing DPR routes...');
    const router = express.Router({ mergeParams: true });
    // ensures that this route matches `/`
    router.get('/', (_req, _res, next) => next());
    router.use('/', setUpNestedRoute.default(), routes$1.Routes(routeImportParams), errorRequestHandler(routeImportParams.layoutPath));
    return router;
}

exports.default = routes;
exports.errorRequestHandler = errorRequestHandler;
exports.routes = routes;
//# sourceMappingURL=index.js.map
