From 7fb9fc4e357f08d85951baa667a8f608cb5d1d76 Mon Sep 17 00:00:00 2001 From: George Goodall Date: Fri, 18 Oct 2024 10:33:05 +0100 Subject: [PATCH] make sure to show the http error page --- src/middleware/common.middleware.js | 11 +++++++++-- src/middleware/datasetOverview.middleware.js | 8 +++++--- src/middleware/datasetTaskList.middleware.js | 9 +-------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/middleware/common.middleware.js b/src/middleware/common.middleware.js index 27e96c22..aeab97eb 100644 --- a/src/middleware/common.middleware.js +++ b/src/middleware/common.middleware.js @@ -1,7 +1,7 @@ import logger from '../utils/logger.js' import { types } from '../utils/logging.js' import performanceDbApi from '../services/performanceDbApi.js' -import { fetchOne, FetchOptions, FetchOneFallbackPolicy, fetchMany } from './middleware.builders.js' +import { fetchOne, FetchOptions, FetchOneFallbackPolicy, fetchMany, renderTemplate } from './middleware.builders.js' import * as v from 'valibot' /** @@ -47,7 +47,8 @@ export const isResourceIdInParams = ({ params }) => !('resourceId' in params) */ export const fetchLatestResource = fetchOne({ query: ({ params }) => performanceDbApi.latestResourceQuery(params.lpa, params.dataset), - result: 'resource' + result: 'resource', + fallbackPolicy: FetchOneFallbackPolicy.continue }) export const takeResourceIdFromParams = (req) => { @@ -96,3 +97,9 @@ export const fetchLpaDatasetIssues = fetchMany({ query: ({ params, req }) => performanceDbApi.datasetIssuesQuery(req.resourceStatus.resource, params.dataset), result: 'issues' }) + +export const getDatasetTaskListError = renderTemplate({ + templateParams: (req) => req.templateParams, + template: 'organisations/http-error.html', + handlerName: 'getDatasetTaskListError' +}) diff --git a/src/middleware/datasetOverview.middleware.js b/src/middleware/datasetOverview.middleware.js index 54d65ad4..cbcf67d9 100644 --- a/src/middleware/datasetOverview.middleware.js +++ b/src/middleware/datasetOverview.middleware.js @@ -1,6 +1,6 @@ -import { fetchDatasetInfo, fetchLatestResource, fetchLpaDatasetIssues, fetchOrgInfo, isResourceAccessible, isResourceIdInParams, logPageError, takeResourceIdFromParams } from './common.middleware.js' -import { fetchOne, fetchIf, fetchMany, renderTemplate, FetchOptions } from './middleware.builders.js' -import { fetchResourceStatus } from './datasetTaskList.middleware.js' +import { fetchDatasetInfo, fetchLatestResource, fetchLpaDatasetIssues, fetchOrgInfo, getDatasetTaskListError, isResourceAccessible, isResourceIdInParams, isResourceNotAccessible, logPageError, takeResourceIdFromParams } from './common.middleware.js' +import { fetchOne, fetchIf, fetchMany, renderTemplate, FetchOptions, onlyIf } from './middleware.builders.js' +import { fetchResourceStatus, prepareDatasetTaskListErrorTemplateParams } from './datasetTaskList.middleware.js' import performanceDbApi from '../services/performanceDbApi.js' const fetchColumnSummary = fetchMany({ @@ -177,6 +177,8 @@ export default [ fetchResourceStatus, fetchIf(isResourceIdInParams, fetchLatestResource, takeResourceIdFromParams), fetchIf(isResourceAccessible, fetchLpaDatasetIssues), + onlyIf(isResourceNotAccessible, prepareDatasetTaskListErrorTemplateParams), + onlyIf(isResourceNotAccessible, getDatasetTaskListError), fetchSpecification, pullOutDatasetSpecification, fetchSources, diff --git a/src/middleware/datasetTaskList.middleware.js b/src/middleware/datasetTaskList.middleware.js index e77d3b1a..f77db39e 100644 --- a/src/middleware/datasetTaskList.middleware.js +++ b/src/middleware/datasetTaskList.middleware.js @@ -1,4 +1,4 @@ -import { fetchDatasetInfo, isResourceAccessible, isResourceNotAccessible, fetchLatestResource, fetchEntityCount, logPageError, fetchLpaDatasetIssues, validateQueryParams } from './common.middleware.js' +import { fetchDatasetInfo, isResourceAccessible, isResourceNotAccessible, fetchLatestResource, fetchEntityCount, logPageError, fetchLpaDatasetIssues, validateQueryParams, getDatasetTaskListError } from './common.middleware.js' import { fetchOne, fetchIf, onlyIf, renderTemplate } from './middleware.builders.js' import performanceDbApi from '../services/performanceDbApi.js' import { statusToTagClass } from '../filters/filters.js' @@ -106,12 +106,6 @@ export const prepareDatasetTaskListErrorTemplateParams = (req, res, next) => { next() } -const getDatasetTaskListError = renderTemplate({ - templateParams: (req) => req.templateParams, - template: 'organisations/http-error.html', - handlerName: 'getDatasetTaskListError' -}) - const validateParams = validateQueryParams({ schema: v.object({ lpa: v.string(), @@ -129,7 +123,6 @@ export default [ fetchIf(isResourceAccessible, fetchEntityCount), onlyIf(isResourceAccessible, prepareDatasetTaskListTemplateParams), onlyIf(isResourceAccessible, getDatasetTaskList), - onlyIf(isResourceNotAccessible, prepareDatasetTaskListErrorTemplateParams), onlyIf(isResourceNotAccessible, getDatasetTaskListError), logPageError