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 #589 from companieshouse/bug/IDVA5-915-401-error-o…
…auth-token-expiry Handling 401 http status code
- Loading branch information
Showing
58 changed files
with
237 additions
and
318 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
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,37 @@ | ||
import type { ErrorRequestHandler, NextFunction, Request, Response } from "express"; | ||
import { CsrfError } from "@companieshouse/web-security-node"; | ||
import { ErrorService } from "../services/errorService"; | ||
import { getLocalesService, selectLang } from "../utils/localise"; | ||
import logger from "../utils/logger"; | ||
import { CHS_URL } from "../utils/properties"; | ||
import { BASE_URL, CHECK_SAVED_APPLICATION } from "../types/pageURL"; | ||
|
||
export const httpErrorHandler: ErrorRequestHandler = (err: any, req: Request, res: Response, next: NextFunction) => { | ||
if (err.httpStatusCode === 401) { | ||
logger.errorRequest( | ||
req, | ||
`A ${err.httpStatusCode} error occurred when a ${req.method} request was made to ${req.originalUrl}. Re-directing to ${BASE_URL}${CHECK_SAVED_APPLICATION}` | ||
); | ||
res.redirect(`${CHS_URL}/signin?return_to=${BASE_URL}${CHECK_SAVED_APPLICATION}`); | ||
} else { | ||
next(err); | ||
} | ||
}; | ||
|
||
export const csrfErrorHandler: ErrorRequestHandler = (err: any, req: Request, res: Response, next:NextFunction) => { | ||
if (err instanceof CsrfError) { | ||
logger.error(`${err.name} - appError: ${err.message} - ${err.stack}`); | ||
const errorService = new ErrorService(); | ||
errorService.render403Page(res, getLocalesService(), selectLang(req.query.lang), req.url); | ||
} else { | ||
next(err); | ||
} | ||
}; | ||
|
||
export const unhandledErrorHandler: ErrorRequestHandler = (err: Error, req: Request, res: Response, next: NextFunction) => { | ||
logger.error(`${err.name} - appError: ${err.message} - ${err.stack}`); | ||
const errorService = new ErrorService(); | ||
errorService.renderErrorPage(res, getLocalesService(), selectLang(req.query.lang), req.url); | ||
}; | ||
|
||
export default [httpErrorHandler, csrfErrorHandler, unhandledErrorHandler]; |
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
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
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
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
Oops, something went wrong.