forked from hyperledger/cacti
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build(deps): upgrade to TS 4.4 test-plugin-ledger-connector-besu
WORK IN PROGRESS Fixes hyperledger#1747 Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
- Loading branch information
Showing
8 changed files
with
152 additions
and
84 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
35 changes: 35 additions & 0 deletions
35
packages/cactus-core/src/main/typescript/web-services/handle-rest-endpoint-exception.ts
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,35 @@ | ||
import { | ||
Logger, | ||
createRuntimeErrorWithCause, | ||
} from "@hyperledger/cactus-common"; | ||
import type { Response } from "express"; | ||
import createHttpError from "http-errors"; | ||
|
||
export interface IHandleRestEndpointExceptionOptions { | ||
readonly errorMsg: string; | ||
readonly log: Logger; | ||
readonly error: unknown; | ||
readonly res: Response; | ||
} | ||
|
||
export function handleRestEndpointException( | ||
ctx: Readonly<IHandleRestEndpointExceptionOptions>, | ||
): void { | ||
if (createHttpError.isHttpError(ctx.error)) { | ||
ctx.log.debug(ctx.errorMsg, ctx.error); | ||
ctx.res.status(ctx.error.statusCode); | ||
if (ctx.error.expose) { | ||
ctx.res.json({ | ||
message: ctx.error.message, | ||
error: ctx.error, | ||
}); | ||
} | ||
} else { | ||
ctx.log.error(ctx.errorMsg, ctx.error); | ||
const rex = createRuntimeErrorWithCause(ctx.errorMsg, ctx.error); | ||
ctx.res.status(500).json({ | ||
message: "Internal Server Error", | ||
error: rex, | ||
}); | ||
} | ||
} |
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