Skip to content

Commit

Permalink
wrap back link extraction in a try/catch
Browse files Browse the repository at this point in the history
  • Loading branch information
rosado committed Oct 24, 2024
1 parent a362b24 commit cd70737
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/controllers/pageController.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import hmpoFormWizard from 'hmpo-form-wizard'
import { logPageView } from '../utils/logging.js'
import { logPageView, types } from '../utils/logging.js'
import logger from '../utils/logger.js'
const { Controller } = hmpoFormWizard

/**
Expand Down Expand Up @@ -32,17 +33,25 @@ class PageController extends Controller {
}

locals (req, res, next) {
let backLink
const deepLinkInfo = req?.sessionModel?.get(this.checkToolDeepLinkSessionKey)
if (deepLinkInfo) {
req.form.options.deepLink = deepLinkInfo
backLink = wizardBackLink(req.originalUrl, deepLinkInfo)
}
try {
let backLink
const deepLinkInfo = req?.sessionModel?.get(this.checkToolDeepLinkSessionKey)
if (deepLinkInfo) {
req.form.options.deepLink = deepLinkInfo
backLink = wizardBackLink(req.originalUrl, deepLinkInfo)
}

backLink = backLink ?? this.options.backLink
if (backLink) {
req.form.options.lastPage = backLink
backLink = backLink ?? this.options.backLink
if (backLink) {
req.form.options.lastPage = backLink
}
} catch (e) {
logger.warn('PageController.locals(): error setting back link', {
type: types.App,
errorMessage: e.message
})
}

super.locals(req, res, next)
}
}
Expand Down

0 comments on commit cd70737

Please sign in to comment.