-
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.
- Loading branch information
1 parent
b7b5c63
commit 4f4f8e5
Showing
15 changed files
with
155 additions
and
19 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,29 @@ | ||
import { IncomingMessage, ServerResponse } from "http"; | ||
import { ErrorHandler } from "prxi"; | ||
import { sendErrorResponse } from "../utils/ResponseUtils"; | ||
import { sendErrorResponse, sendRedirect } from "../utils/ResponseUtils"; | ||
import getLogger from "../Logger"; | ||
import { getConfig } from "../config/getConfig"; | ||
|
||
export const errorHandler: ErrorHandler = async (req: IncomingMessage, res: ServerResponse, err: Error) => { | ||
console.log(err); | ||
const logger = getLogger('ErrorHandler'); | ||
logger.child({ error: err.message }).error('Unexpected error occurred'); | ||
await sendErrorResponse(req, 500, 'Unexpected error occurred', res); | ||
|
||
let code = 500; | ||
let message = 'Unexpected error occurred'; | ||
let redirectTo = getConfig().redirect.pageRequest.e500; | ||
|
||
if ((<any> err).code === 'ECONNREFUSED') { | ||
code = 503; | ||
message = 'Service Unavailable'; | ||
redirectTo = getConfig().redirect.pageRequest.e503; | ||
} | ||
|
||
if (redirectTo) { | ||
sendRedirect(req, res, redirectTo); | ||
return; | ||
} | ||
|
||
await sendErrorResponse(req, code, message, res); | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { suite, test } from "@testdeck/mocha"; | ||
import { BaseSuite } from "./Base.suite"; | ||
import { getConfig } from "../src/config/getConfig"; | ||
import { strictEqual } from "assert"; | ||
|
||
@suite() | ||
class ErrorHandlerSuite extends BaseSuite { | ||
@test() | ||
async e503() { | ||
await this.reloadPrxiWith({ | ||
// set incorrect upstream | ||
upstream: getConfig().upstream + 1, | ||
}) | ||
|
||
await this.withNewPage(getConfig().hostURL + '/pages/test', async (page) => { | ||
await this.loginOnKeycloak(page); | ||
|
||
const text = await this.getTextFromPage(page); | ||
strictEqual(text, '503: Service Unavailable') | ||
}); | ||
} | ||
|
||
@test() | ||
async e503WithRedirect() { | ||
await this.reloadPrxiWith({ | ||
// set incorrect upstream | ||
upstream: getConfig().upstream + 1, | ||
redirect: { | ||
pageRequest: { | ||
e503: getConfig().upstream + '/api/test' | ||
} | ||
} | ||
}) | ||
|
||
await this.withNewPage(getConfig().hostURL + '/pages/test', async (page) => { | ||
await this.loginOnKeycloak(page); | ||
|
||
const json = await this.getJsonFromPage(page); | ||
strictEqual(json.http.originalUrl, '/api/test'); | ||
}); | ||
} | ||
} |
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