generated from companieshouse/node-review-web-starter-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #193 from companieshouse/feature/IDVA3-2554-404-sc…
…reen IDVA3-2554 Create 'Page not found' 404 error screen
- Loading branch information
Showing
10 changed files
with
88 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"404_main_title": "404_main_title: To be translated", | ||
"404_check_typed_address": "404_check_typed_address: To be translated", | ||
"404_check_pasted_address": "404_check_pasted_address: To be translated", | ||
"404_arrived_via_bad_url_1": "404_arrived_via_bad_link: To be translated", | ||
"404_arrived_via_bad_url_2": "404_arrived_via_bad_link: To be translated" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"404_main_title": "Page not found", | ||
"404_check_typed_address": "If you typed the web address, check it is correct.", | ||
"404_check_pasted_address": "If you pasted the web address, check you copied the entire address.", | ||
"404_arrived_via_bad_url_1": "Contact us", | ||
"404_arrived_via_bad_url_2": "if you need to speak to someone about providing identity verification details for a person with significant control." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
import { HttpStatusCode } from "axios"; | ||
import { Request, Response } from "express"; | ||
import PageNotFoundHandler from "../routers/handlers/error/pageNotFoundHandler"; | ||
|
||
export const pageNotFound = (req: Request, res: Response) => { | ||
|
||
const handler = new PageNotFoundHandler(); | ||
handler.executeGet(req, res).then((viewModel) => { | ||
const { templatePath, viewData } = viewModel; | ||
res.status(HttpStatusCode.NotFound).render(templatePath, viewData); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Request, Response } from "express"; | ||
import { Urls } from "../../../constants"; | ||
import { logger } from "../../../lib/logger"; | ||
import { getLocaleInfo, getLocalesService, selectLang } from "../../../utils/localise"; | ||
import { BaseViewData, GenericHandler, ViewModel } from "../generic"; | ||
import { env } from "../../../config"; | ||
|
||
interface PageNotFoundViewData extends BaseViewData { | ||
extraData?: string[]; | ||
} | ||
|
||
export default class PageNotFoundHandler extends GenericHandler<PageNotFoundViewData> { | ||
|
||
public static templatePath = "router_views/error/page-not-found"; | ||
|
||
public async getViewData (req: Request, res: Response): Promise<PageNotFoundViewData> { | ||
const baseViewData = await super.getViewData(req, res); | ||
// adding language functionality | ||
const lang = selectLang(req.query.lang); | ||
const locales = getLocalesService(); | ||
|
||
return { | ||
...baseViewData, | ||
...getLocaleInfo(locales, lang), | ||
isSignedIn: false, | ||
currentUrl: req.url, | ||
backURL: null, | ||
templateName: Urls.PAGE_NOT_FOUND, | ||
extraData: [env.CONTACT_US_LINK] | ||
}; | ||
} | ||
|
||
public async executeGet (req: Request, res: Response): Promise<ViewModel<PageNotFoundViewData>> { | ||
logger.info(`${PageNotFoundHandler.name} - ${this.executeGet.name}: called to serve 404 error page`); | ||
|
||
// ...process request here and return data for the view | ||
return { | ||
templatePath: PageNotFoundHandler.templatePath, | ||
viewData: await this.getViewData(req, res) | ||
}; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
{% extends "layouts/default.njk" %} | ||
|
||
{% set title = i18n.404_main_title %} | ||
|
||
{% block main_content %} | ||
<h1 class="govuk-heading-l">{{ title }}</h1> | ||
<p class="govuk-body">{{ i18n.404_check_typed_address }}</p> | ||
<p class="govuk-body">{{ i18n.404_check_pasted_address }}</p> | ||
<p class="govuk-body"> | ||
<a href="{{ extraData[0] }}">{{ i18n.404_arrived_via_bad_url_1 }}</a> {{ i18n.404_arrived_via_bad_url_2 }} | ||
</p> | ||
{% endblock %} |