import { Router } from 'express';
import { captureException } from '@sentry/node';
import logger from '../utils/logger.js';
import { Routes } from './journeys/routes.js';
import setupNestedRoute from '../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',
        });
    }
    captureException(error);
    if (error.status >= 400) {
        return res.render('dpr/routes/serviceProblem.njk', {
            layoutPath,
        });
    }
    return next(error);
};
function routes(routeImportParams) {
    logger.info('Initialiasing DPR routes...');
    const router = Router({ mergeParams: true });
    // ensures that this route matches `/`
    router.get('/', (_req, _res, next) => next());
    router.use('/', setupNestedRoute(), Routes(routeImportParams), errorRequestHandler(routeImportParams.layoutPath));
    return router;
}

export { routes as default, errorRequestHandler, routes };
//# sourceMappingURL=index.js.map
