Skip to content

Commit

Permalink
Merge pull request #562 from digital-land/hotfix-http-error-page
Browse files Browse the repository at this point in the history
make sure to show the http error page
  • Loading branch information
GeorgeGoodall-GovUk authored Oct 18, 2024
2 parents 4ea328f + 7fb9fc4 commit 7f4c591
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
11 changes: 9 additions & 2 deletions src/middleware/common.middleware.js
Original file line number Diff line number Diff line change
@@ -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'

/**
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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'
})
8 changes: 5 additions & 3 deletions src/middleware/datasetOverview.middleware.js
Original file line number Diff line number Diff line change
@@ -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({
Expand Down Expand Up @@ -177,6 +177,8 @@ export default [
fetchResourceStatus,
fetchIf(isResourceIdInParams, fetchLatestResource, takeResourceIdFromParams),
fetchIf(isResourceAccessible, fetchLpaDatasetIssues),
onlyIf(isResourceNotAccessible, prepareDatasetTaskListErrorTemplateParams),
onlyIf(isResourceNotAccessible, getDatasetTaskListError),
fetchSpecification,
pullOutDatasetSpecification,
fetchSources,
Expand Down
9 changes: 1 addition & 8 deletions src/middleware/datasetTaskList.middleware.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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(),
Expand All @@ -129,7 +123,6 @@ export default [
fetchIf(isResourceAccessible, fetchEntityCount),
onlyIf(isResourceAccessible, prepareDatasetTaskListTemplateParams),
onlyIf(isResourceAccessible, getDatasetTaskList),

onlyIf(isResourceNotAccessible, prepareDatasetTaskListErrorTemplateParams),
onlyIf(isResourceNotAccessible, getDatasetTaskListError),
logPageError
Expand Down

0 comments on commit 7f4c591

Please sign in to comment.