diff --git a/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/deploy-contract-go-source/deploy-contract-go-source-endpoint-v1.ts b/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/deploy-contract-go-source/deploy-contract-go-source-endpoint-v1.ts index f327b6cef6..8d8a6cca28 100644 --- a/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/deploy-contract-go-source/deploy-contract-go-source-endpoint-v1.ts +++ b/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/deploy-contract-go-source/deploy-contract-go-source-endpoint-v1.ts @@ -16,7 +16,10 @@ import { IEndpointAuthzOptions, } from "@hyperledger/cactus-core-api"; -import { registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginLedgerConnectorFabric } from "../plugin-ledger-connector-fabric"; import { DeployContractGoSourceV1Request } from "../generated/openapi/typescript-axios/index"; @@ -106,8 +109,8 @@ export class DeployContractGoSourceEndpointV1 implements IWebServiceEndpoint { async handleRequest(req: Request, res: Response): Promise { const fnTag = `${this.className}#handleRequest()`; const verbUpper = this.getVerbLowerCase().toUpperCase(); - this.log.debug(`${verbUpper} ${this.getPath()}`); - + const reqTag = `${verbUpper} ${this.getPath()}`; + this.log.debug(reqTag); try { const { connector } = this.opts; const reqBody = req.body as DeployContractGoSourceV1Request; @@ -116,10 +119,13 @@ export class DeployContractGoSourceEndpointV1 implements IWebServiceEndpoint { res.status(HttpStatus.OK); res.json(resBody); } catch (ex) { - this.log.error(`${fnTag} failed to serve contract deploy request`, ex); - res.status(HttpStatus.INTERNAL_SERVER_ERROR); - res.statusMessage = ex.message; - res.json({ error: ex.stack }); + const errorMsg = `${fnTag} request handler fn crashed for: ${reqTag}`; + await handleRestEndpointException({ + errorMsg, + log: this.log, + error: ex, + res, + }); } } } diff --git a/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/deploy-contract/deploy-contract-endpoint-v1.ts b/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/deploy-contract/deploy-contract-endpoint-v1.ts index 55a8d5d4d7..837c3f8008 100644 --- a/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/deploy-contract/deploy-contract-endpoint-v1.ts +++ b/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/deploy-contract/deploy-contract-endpoint-v1.ts @@ -15,7 +15,10 @@ import { IEndpointAuthzOptions, } from "@hyperledger/cactus-core-api"; -import { registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginLedgerConnectorFabric } from "../plugin-ledger-connector-fabric"; import { DeployContractV1Request } from "../generated/openapi/typescript-axios/index"; @@ -87,7 +90,8 @@ export class DeployContractEndpointV1 implements IWebServiceEndpoint { async handleRequest(req: Request, res: Response): Promise { const fnTag = `${this.className}#handleRequest()`; const verbUpper = this.getVerbLowerCase().toUpperCase(); - this.log.debug(`${verbUpper} ${this.getPath()}`); + const reqTag = `${verbUpper} ${this.getPath()}`; + this.log.debug(reqTag); try { const { connector } = this.opts; @@ -96,10 +100,13 @@ export class DeployContractEndpointV1 implements IWebServiceEndpoint { res.status(HttpStatus.OK); res.json(resBody); } catch (ex) { - this.log.error(`${fnTag} failed to serve contract deploy request`, ex); - res.status(HttpStatus.INTERNAL_SERVER_ERROR); - res.statusMessage = ex.message; - res.json({ error: ex.stack }); + const errorMsg = `${fnTag} request handler fn crashed for: ${reqTag}`; + await handleRestEndpointException({ + errorMsg, + log: this.log, + error: ex, + res, + }); } } } diff --git a/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/get-block/get-block-endpoint-v1.ts b/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/get-block/get-block-endpoint-v1.ts index b9399d5f51..6bb9aa1cf0 100644 --- a/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/get-block/get-block-endpoint-v1.ts +++ b/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/get-block/get-block-endpoint-v1.ts @@ -28,10 +28,16 @@ export interface IGetBlockEndpointV1Options { } export class GetBlockEndpointV1 implements IWebServiceEndpoint { + public static readonly CLASS_NAME = "GetBlockEndpointV1"; + private readonly log: Logger; + public get className(): string { + return GetBlockEndpointV1.CLASS_NAME; + } + constructor(public readonly opts: IGetBlockEndpointV1Options) { - const fnTag = "GetBlockEndpointV1#constructor()"; + const fnTag = `${this.className}#constructor()`; Checks.truthy(opts, `${fnTag} options`); Checks.truthy(opts.connector, `${fnTag} options.connector`); @@ -84,14 +90,21 @@ export class GetBlockEndpointV1 implements IWebServiceEndpoint { } async handleRequest(req: Request, res: Response): Promise { - const fnTag = "GetBlockEndpointV1#handleRequest()"; - this.log.debug(`POST ${this.getPath()}`); + const fnTag = `${this.className}#handleRequest()`; + const verbUpper = this.getVerbLowerCase().toUpperCase(); + const reqTag = `${verbUpper} ${this.getPath()}`; + this.log.debug(reqTag); try { res.status(200).send(await this.opts.connector.getBlock(req.body)); - } catch (error) { - const errorMsg = `Crash while serving ${fnTag}`; - handleRestEndpointException({ errorMsg, log: this.log, error, res }); + } catch (ex) { + const errorMsg = `${fnTag} request handler fn crashed for: ${reqTag}`; + await handleRestEndpointException({ + errorMsg, + log: this.log, + error: ex, + res, + }); } } } diff --git a/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/get-prometheus-exporter-metrics/get-prometheus-exporter-metrics-endpoint-v1.ts b/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/get-prometheus-exporter-metrics/get-prometheus-exporter-metrics-endpoint-v1.ts index 4886332e7e..2834afb1b4 100644 --- a/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/get-prometheus-exporter-metrics/get-prometheus-exporter-metrics-endpoint-v1.ts +++ b/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/get-prometheus-exporter-metrics/get-prometheus-exporter-metrics-endpoint-v1.ts @@ -16,7 +16,10 @@ import { import OAS from "../../json/openapi.json"; -import { registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginLedgerConnectorFabric } from "../plugin-ledger-connector-fabric"; @@ -28,12 +31,18 @@ export interface IGetPrometheusExporterMetricsEndpointV1Options { export class GetPrometheusExporterMetricsEndpointV1 implements IWebServiceEndpoint { + public static readonly CLASS_NAME = "GetPrometheusExporterMetricsEndpointV1"; + private readonly log: Logger; + public get className(): string { + return GetPrometheusExporterMetricsEndpointV1.CLASS_NAME; + } + constructor( public readonly opts: IGetPrometheusExporterMetricsEndpointV1Options, ) { - const fnTag = "GetPrometheusExporterMetricsEndpointV1#constructor()"; + const fnTag = `${this.className}#constructor()`; Checks.truthy(opts, `${fnTag} options`); Checks.truthy(opts.connector, `${fnTag} options.connector`); @@ -83,19 +92,23 @@ export class GetPrometheusExporterMetricsEndpointV1 } async handleRequest(req: Request, res: Response): Promise { - const fnTag = "GetPrometheusExporterMetrics#handleRequest()"; + const fnTag = `${this.className}#handleRequest()`; const verbUpper = this.getVerbLowerCase().toUpperCase(); - this.log.debug(`${verbUpper} ${this.getPath()}`); + const reqTag = `${verbUpper} ${this.getPath()}`; + this.log.debug(reqTag); try { const resBody = await this.opts.connector.getPrometheusExporterMetrics(); res.status(200); res.send(resBody); } catch (ex) { - this.log.error(`${fnTag} failed to serve request`, ex); - res.status(500); - res.statusMessage = ex.message; - res.json({ error: ex.stack }); + const errorMsg = `${fnTag} request handler fn crashed for: ${reqTag}`; + await handleRestEndpointException({ + errorMsg, + log: this.log, + error: ex, + res, + }); } } } diff --git a/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/get-transaction-receipt/get-transaction-receipt-by-txid-endpoint-v1.ts b/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/get-transaction-receipt/get-transaction-receipt-by-txid-endpoint-v1.ts index 7f05408ea4..a384eee825 100644 --- a/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/get-transaction-receipt/get-transaction-receipt-by-txid-endpoint-v1.ts +++ b/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/get-transaction-receipt/get-transaction-receipt-by-txid-endpoint-v1.ts @@ -14,7 +14,10 @@ import { IEndpointAuthzOptions, } from "@hyperledger/cactus-core-api"; -import { registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginLedgerConnectorFabric } from "../plugin-ledger-connector-fabric"; import { RunTransactionRequest } from "../generated/openapi/typescript-axios"; @@ -28,10 +31,16 @@ export interface IRunTransactionEndpointV1Options { export class GetTransactionReceiptByTxIDEndpointV1 implements IWebServiceEndpoint { + public static readonly CLASS_NAME = "GetTransactionReceiptByTxIDEndpointV1"; + private readonly log: Logger; + public get className(): string { + return GetTransactionReceiptByTxIDEndpointV1.CLASS_NAME; + } + constructor(public readonly opts: IRunTransactionEndpointV1Options) { - const fnTag = "GetTransactionReceiptByTxIDEndpointV1#constructor()"; + const fnTag = `${this.className}#constructor()`; Checks.truthy(opts, `${fnTag} options`); Checks.truthy(opts.connector, `${fnTag} options.connector`); @@ -84,8 +93,10 @@ export class GetTransactionReceiptByTxIDEndpointV1 } async handleRequest(req: Request, res: Response): Promise { - const fnTag = "GetTransactionReceiptByTxIDEndpointV1#handleRequest()"; - this.log.debug(`POST ${this.getPath()}`); + const fnTag = `${this.className}#handleRequest()`; + const verbUpper = this.getVerbLowerCase().toUpperCase(); + const reqTag = `${verbUpper} ${this.getPath()}`; + this.log.debug(reqTag); try { const reqBody = req.body as RunTransactionRequest; @@ -94,10 +105,13 @@ export class GetTransactionReceiptByTxIDEndpointV1 res.status(200); res.json(resBody); } catch (ex) { - this.log.error(`${fnTag} failed to serve request`, ex); - res.status(500); - res.statusMessage = ex.message; - res.json({ error: ex.stack }); + const errorMsg = `${fnTag} request handler fn crashed for: ${reqTag}`; + await handleRestEndpointException({ + errorMsg, + log: this.log, + error: ex, + res, + }); } } } diff --git a/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/run-transaction/run-delegated-sign-transaction-endpoint-v1.ts b/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/run-transaction/run-delegated-sign-transaction-endpoint-v1.ts index 257150c2e3..0302e42b3c 100644 --- a/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/run-transaction/run-delegated-sign-transaction-endpoint-v1.ts +++ b/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/run-transaction/run-delegated-sign-transaction-endpoint-v1.ts @@ -6,7 +6,6 @@ import { LogLevelDesc, Checks, IAsyncProvider, - safeStringifyException, } from "@hyperledger/cactus-common"; import { @@ -15,7 +14,10 @@ import { IEndpointAuthzOptions, } from "@hyperledger/cactus-core-api"; -import { registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginLedgerConnectorFabric } from "../plugin-ledger-connector-fabric"; import OAS from "../../json/openapi.json"; @@ -28,13 +30,18 @@ export interface IRunDelegatedSignTransactionEndpointV1Options { export class RunDelegatedSignTransactionEndpointV1 implements IWebServiceEndpoint { + public static readonly CLASS_NAME = "RunDelegatedSignTransactionEndpointV1"; + private readonly log: Logger; + public get className(): string { + return RunDelegatedSignTransactionEndpointV1.CLASS_NAME; + } + constructor( public readonly opts: IRunDelegatedSignTransactionEndpointV1Options, ) { - const fnTag = "RunDelegatedSignTransactionEndpointV1#constructor()"; - + const fnTag = `${this.className}#constructor()`; Checks.truthy(opts, `${fnTag} options`); Checks.truthy(opts.connector, `${fnTag} options.connector`); @@ -84,18 +91,22 @@ export class RunDelegatedSignTransactionEndpointV1 } async handleRequest(req: Request, res: Response): Promise { - const fnTag = "RunDelegatedSignTransactionEndpointV1#handleRequest()"; - this.log.debug(`POST ${this.getPath()}`); + const fnTag = `${this.className}#handleRequest()`; + const verbUpper = this.getVerbLowerCase().toUpperCase(); + const reqTag = `${verbUpper} ${this.getPath()}`; + this.log.debug(reqTag); try { res .status(200) .json(await this.opts.connector.transactDelegatedSign(req.body)); - } catch (error) { - this.log.error(`Crash while serving ${fnTag}`, error); - res.status(500).json({ - message: "Internal Server Error", - error: safeStringifyException(error), + } catch (ex) { + const errorMsg = `${fnTag} request handler fn crashed for: ${reqTag}`; + await handleRestEndpointException({ + errorMsg, + log: this.log, + error: ex, + res, }); } } diff --git a/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/run-transaction/run-transaction-endpoint-v1.ts b/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/run-transaction/run-transaction-endpoint-v1.ts index 38173ef24d..adf9961a58 100644 --- a/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/run-transaction/run-transaction-endpoint-v1.ts +++ b/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/run-transaction/run-transaction-endpoint-v1.ts @@ -6,7 +6,6 @@ import { LogLevelDesc, Checks, IAsyncProvider, - safeStringifyException, } from "@hyperledger/cactus-common"; import { @@ -15,7 +14,10 @@ import { IEndpointAuthzOptions, } from "@hyperledger/cactus-core-api"; -import { registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginLedgerConnectorFabric } from "../plugin-ledger-connector-fabric"; import OAS from "../../json/openapi.json"; @@ -26,10 +28,16 @@ export interface IRunTransactionEndpointV1Options { } export class RunTransactionEndpointV1 implements IWebServiceEndpoint { + public static readonly CLASS_NAME = "RunTransactionEndpointV1"; + private readonly log: Logger; + public get className(): string { + return RunTransactionEndpointV1.CLASS_NAME; + } + constructor(public readonly opts: IRunTransactionEndpointV1Options) { - const fnTag = "RunTransactionEndpointV1#constructor()"; + const fnTag = `${this.className}#constructor()`; Checks.truthy(opts, `${fnTag} options`); Checks.truthy(opts.connector, `${fnTag} options.connector`); @@ -80,16 +88,20 @@ export class RunTransactionEndpointV1 implements IWebServiceEndpoint { } async handleRequest(req: Request, res: Response): Promise { - const fnTag = "RunTransactionEndpointV1#handleRequest()"; - this.log.debug(`POST ${this.getPath()}`); + const fnTag = `${this.className}#handleRequest()`; + const verbUpper = this.getVerbLowerCase().toUpperCase(); + const reqTag = `${verbUpper} ${this.getPath()}`; + this.log.debug(reqTag); try { res.status(200).json(await this.opts.connector.transact(req.body)); - } catch (error) { - this.log.error(`Crash while serving ${fnTag}`, error); - res.status(500).json({ - message: "Internal Server Error", - error: safeStringifyException(error), + } catch (ex) { + const errorMsg = `${fnTag} request handler fn crashed for: ${reqTag}`; + await handleRestEndpointException({ + errorMsg, + log: this.log, + error: ex, + res, }); } }