From af39d46761d6063ab9266f1a1166209b14e7a713 Mon Sep 17 00:00:00 2001 From: Tomasz Awramski Date: Wed, 22 May 2024 17:50:17 +0200 Subject: [PATCH] prettier and endpoint catch handling fix --- .../admin-enroll-v1-endpoint.test.ts | 10 +- .../run-discounted-asset-trade-client.ts | 7 +- .../counterparty-htlc-endpoint.ts | 8 +- .../web-services/own-htlc-endpoint.ts | 7 +- .../web-services/get-object-endpoint-v1.ts | 11 +- .../web-services/has-object-endpoint-v1.ts | 11 +- .../web-services/set-object-endpoint-v1.ts | 11 +- .../default-consortium-provider.test.ts | 39 +- .../watch-healthcheck-v1-endpoint.ts | 3 +- .../web-services/deploy-contract-endpoint.ts | 12 +- .../web-services/run-transaction-endpoint.ts | 12 +- .../unprotected-action-endpoint.ts | 12 +- .../routing-interface/routes/login.ts | 8 +- .../get-consortium-jws-endpoint-v1.ts | 4 +- .../consortium/get-node-jws-endpoint-v1.ts | 2 +- ...prometheus-exporter-metrics-endpoint-v1.ts | 10 +- .../get-single-status-endpoint.ts | 7 +- .../web-services/get-status-endpoint.ts | 7 +- .../web-services/initialize-endpoint.ts | 7 +- .../web-services/new-contract-endpoint.ts | 7 +- .../web-services/refund-endpoint.ts | 7 +- .../web-services/withdraw-endpoint.ts | 7 +- .../get-single-status-endpoint.ts | 7 +- .../web-services/get-status-endpoint.ts | 9 +- .../web-services/initialize-endpoint.ts | 9 +- .../web-services/new-contract-endpoint.ts | 11 +- .../web-services/refund-endpoint.ts | 7 +- .../web-services/withdraw-endpoint.ts | 7 +- .../delete-keychain-entry-endpoint-v1.ts | 7 +- .../get-keychain-entry-endpoint-v1.ts | 32 +- ...prometheus-exporter-metrics-endpoint-v1.ts | 31 +- .../has-keychain-entry-endpoint-v1.ts | 7 +- .../set-keychain-entry-endpoint-v1.ts | 7 +- .../delete-keychain-entry-endpoint.ts | 7 +- .../get-keychain-entry-endpoint.ts | 33 +- .../has-keychain-entry-endpoint.ts | 7 +- .../set-keychain-entry-endpoint.ts | 7 +- .../delete-keychain-entry-endpoint-v1.ts | 7 +- .../get-keychain-entry-endpoint-v1.ts | 34 +- .../has-keychain-entry-endpoint-v1.ts | 7 +- .../set-keychain-entry-endpoint-v1.ts | 9 +- .../openapi/openapi-validation.test.ts | 16 +- .../delete-keychain-entry-endpoint-v1.ts | 7 +- .../get-keychain-entry-endpoint-v1.ts | 32 +- .../has-keychain-entry-endpoint-v1.ts | 7 +- .../set-keychain-entry-endpoint-v1.ts | 7 +- ...prometheus-exporter-metrics-endpoint-v1.ts | 37 +- .../main/typescript/plugin-keychain-vault.ts | 7 +- .../delete-keychain-entry-endpoint-v1.ts | 7 +- .../get-keychain-entry-endpoint-v1.ts | 7 +- ...prometheus-exporter-metrics-endpoint-v1.ts | 10 +- .../has-keychain-entry-endpoint-v1.ts | 7 +- .../set-keychain-entry-endpoint-v1.ts | 7 +- .../accept-invitation-v1-endpoint.ts | 13 +- ...e-new-connection-invitation-v1-endpoint.ts | 16 +- .../web-services/get-agents-v1-endpoint.ts | 13 +- .../get-connections-v1-endpoint.ts | 13 +- .../web-services/request-proof-v1-endpoint.ts | 13 +- .../web-services/get-balance-endpoint.ts | 7 +- .../get-besu-record-endpoint-v1.ts | 7 +- .../web-services/get-block-v1-endpoint-.ts | 7 +- .../web-services/get-past-logs-endpoint.ts | 7 +- ...prometheus-exporter-metrics-endpoint-v1.ts | 33 +- .../web-services/get-transaction-endpoint.ts | 7 +- .../web-services/invoke-contract-endpoint.ts | 7 +- .../web-services/run-transaction-endpoint.ts | 7 +- .../sign-transaction-endpoint-v1.ts | 33 +- .../deploy-contract/invoke-contract.test.ts | 12 +- .../openapi/openapi-validation.test.ts | 32 +- .../web-services/get-lineage-v1-endpoint.ts | 13 +- .../register-history-data-v1-endpoint.ts | 12 +- ...earch-lineage-by-globaldata-v1-endpoint.ts | 12 +- .../search-lineage-by-header-v1-endpoint.ts | 13 +- .../deploy-contract-jars-endpoint.ts | 19 +- .../web-services/diagnose-node-endpoint-v1.ts | 24 +- ...prometheus-exporter-metrics-endpoint-v1.ts | 27 +- .../invoke-contract-endpoint-v1.ts | 24 +- .../web-services/list-flows-endpoint-v1.ts | 24 +- .../web-services/network-map-endpoint-v1.ts | 24 +- .../openapi/openapi-validation.test.ts | 15 +- .../plugin-ledger-connector-ethereum.ts | 38 +- ...prometheus-exporter-metrics-v1-endpoint.ts | 35 +- ...oy-and-invoke-using-json-object-v1.test.ts | 6 +- .../deploy-contract-endpoint-v1.ts | 26 +- .../get-block/get-block-endpoint-v1.ts | 16 +- ...prometheus-exporter-metrics-endpoint-v1.ts | 15 +- ...transaction-receipt-by-txid-endpoint-v1.ts | 15 +- .../plugin-ledger-connector-fabric.ts | 61 +- ...-delegated-sign-transaction-endpoint-v1.ts | 14 +- .../run-transaction-endpoint-v1.ts | 14 +- .../openapi/openapi-validation-go.test.ts | 4 +- .../openapi/openapi-validation.test.ts | 8 +- .../generate-transaction-v1-endpoint.ts | 15 +- .../web-services/transact-v1-endpoint.ts | 12 +- ...nerate-and-send-signed-transaction.test.ts | 19 +- .../plugin-ledger-connector-polkadot.ts | 21 +- .../plugin-ledger-connector-quorum.ts | 46 +- ...-solidity-bytecode-endpoint-json-object.ts | 5 +- ...prometheus-exporter-metrics-endpoint-v1.ts | 3 +- .../openapi-validation-no-keychain.test.ts | 8 +- .../openapi/openapi-validation.test.ts | 12 +- .../web-services/status-endpoint-v1.ts | 12 +- ...loy-contract-solidity-bytecode-endpoint.ts | 3 +- ...-solidity-bytecode-json-object-endpoint.ts | 3 +- ...prometheus-exporter-metrics-endpoint-v1.ts | 3 +- .../integration/invoke-contract-xdai.test.ts | 2 +- .../openapi-validation-no-keychain.test.ts | 18 +- .../openapi/openapi-validation.test.ts | 12 +- .../web-services/status-endpoint-v1.ts | 12 +- .../client-side/client-request-endpoint.ts | 6 +- .../commit-final-response-endpoint.ts | 10 +- .../commit-prepare-response-endpoint.ts | 13 +- .../lock-evidence-response-endpoint.ts | 12 +- .../transfer-commence-response-endpoint.ts | 10 +- .../transfer-initiation-response-endpoint.ts | 13 +- .../recovery/recover-message-endpoint.ts | 10 +- .../recover-success-message-endpoint.ts | 10 +- .../recover-update-ack-message-endpoint.ts | 10 +- .../recover-update-message-endpoint.ts | 10 +- .../recovery/rollback-ack-message-endpoint.ts | 10 +- .../recovery/rollback-message-endpoint.ts | 10 +- .../commit-final-request-endpoint.ts | 10 +- .../commite-prepare-request-endpoint.ts | 10 +- .../lock-evidence-request-endpoint.ts | 10 +- .../transfer-commence-request-endpoint.ts | 10 +- .../transfer-complete-request-endpoint.ts | 10 +- .../transfer-initiation-request-endpoint.ts | 13 +- .../openapi/openapi-validation.test.ts | 4 +- .../initialize-endpoint.test.ts | 2 +- .../new-contract-endpoint.test.ts | 2 +- .../openapi/openapi-validation.test.ts | 26 +- .../refund-endpoint-invalid-time.test.ts | 2 +- .../refund-endpoint.test.ts | 2 +- .../withdraw-endpoint-invalid-id.test.ts | 2 +- ...get-single-status-endpoint-invalid.test.ts | 2 +- .../get-status-endpoint-invalid.test.ts | 2 +- .../openapi/openapi-validation.test.ts | 57 +- .../v21-sign-transaction-endpoint.test.ts | 2 +- .../fabric/fabric-test-ledger-v1.ts | 20 +- tools/generate-sbom.ts | 2 +- .../fabric-driver/server/sample-satp.ts | 675 ++++++++++-------- .../drivers/fabric-driver/server/server.ts | 319 +++++---- .../src/SatpAssetManager.ts | 114 ++- 143 files changed, 1698 insertions(+), 1219 deletions(-) diff --git a/examples/cactus-example-carbon-accounting-backend/src/test/typescript/integration/admin-enroll-v1-endpoint.test.ts b/examples/cactus-example-carbon-accounting-backend/src/test/typescript/integration/admin-enroll-v1-endpoint.test.ts index 3e3464a156..b9e8b03afa 100644 --- a/examples/cactus-example-carbon-accounting-backend/src/test/typescript/integration/admin-enroll-v1-endpoint.test.ts +++ b/examples/cactus-example-carbon-accounting-backend/src/test/typescript/integration/admin-enroll-v1-endpoint.test.ts @@ -46,13 +46,13 @@ const log = LoggerProvider.getOrCreate({ level: logLevel, }); -interface ResponseError extends AxiosError { +interface ResponseError extends AxiosError { response: { - data: T; + data: any; status: number; statusText: string; - headers: any - config: any + headers: any; + config: any; request?: any; }; } @@ -193,7 +193,7 @@ test.skip(testCase, async (t: Test) => { await apiClientBad.enrollAdminV1({ orgName: "does-not-matter" }); t.fail("enroll admin response status === 403 FAIL"); } catch (err) { - const e = err as ResponseError + const e = err as ResponseError; t.ok(e, "error thrown for forbidden endpoint truthy OK"); t.ok(e.response, "enroll admin response truthy OK"); diff --git a/examples/cactus-example-discounted-asset-trade-client/src/main/typescript/scripts/run-discounted-asset-trade-client.ts b/examples/cactus-example-discounted-asset-trade-client/src/main/typescript/scripts/run-discounted-asset-trade-client.ts index e58f93e9a3..fb0f742afb 100644 --- a/examples/cactus-example-discounted-asset-trade-client/src/main/typescript/scripts/run-discounted-asset-trade-client.ts +++ b/examples/cactus-example-discounted-asset-trade-client/src/main/typescript/scripts/run-discounted-asset-trade-client.ts @@ -189,7 +189,12 @@ async function menuLoop(agent: AnoncredAgent) { break; } } catch (error) { - if (error && typeof error === 'object' && 'isTtyError' in error && error.isTtyError) { + if ( + error && + typeof error === "object" && + "isTtyError" in error && + error.isTtyError + ) { log.error("Prompt couldn't be rendered in the current environment:"); isRunning = false; } diff --git a/extensions/cactus-plugin-htlc-coordinator-besu/src/main/typescript/web-services/counterparty-htlc-endpoint.ts b/extensions/cactus-plugin-htlc-coordinator-besu/src/main/typescript/web-services/counterparty-htlc-endpoint.ts index 34cf6f7262..3ae184050e 100644 --- a/extensions/cactus-plugin-htlc-coordinator-besu/src/main/typescript/web-services/counterparty-htlc-endpoint.ts +++ b/extensions/cactus-plugin-htlc-coordinator-besu/src/main/typescript/web-services/counterparty-htlc-endpoint.ts @@ -12,10 +12,10 @@ import { LogLevelDesc, LoggerProvider, IAsyncProvider, - safeStringifyException, } from "@hyperledger/cactus-common"; import { PluginRegistry, + handleRestEndpointException, registerWebServiceEndpoint, } from "@hyperledger/cactus-core"; import { CounterpartyHTLCRequest } from "../generated/openapi/typescript-axios"; @@ -109,10 +109,8 @@ export class CounterpartyHTLCEndpoint implements IWebServiceEndpoint { res.json(resBody); } catch (ex) { this.log.error(`Crash while serving ${reqTag}`, ex); - res.status(500).json({ - message: "Internal Server Error", - error: ex, - }); + const errorMsg = "Internal Server Error"; + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/extensions/cactus-plugin-htlc-coordinator-besu/src/main/typescript/web-services/own-htlc-endpoint.ts b/extensions/cactus-plugin-htlc-coordinator-besu/src/main/typescript/web-services/own-htlc-endpoint.ts index db8819867d..3023cfae84 100644 --- a/extensions/cactus-plugin-htlc-coordinator-besu/src/main/typescript/web-services/own-htlc-endpoint.ts +++ b/extensions/cactus-plugin-htlc-coordinator-besu/src/main/typescript/web-services/own-htlc-endpoint.ts @@ -16,6 +16,7 @@ import { import { registerWebServiceEndpoint, PluginRegistry, + handleRestEndpointException, } from "@hyperledger/cactus-core"; import { PluginHTLCCoordinatorBesu } from "../plugin-htlc-coordinator-besu"; import { OwnHTLCRequest } from "../generated/openapi/typescript-axios"; @@ -103,10 +104,8 @@ export class OwnHTLCEndpoint implements IWebServiceEndpoint { res.json(resBody); } catch (ex) { this.log.error(`Crash while serving ${reqTag}`, ex); - res.status(500).json({ - message: "Internal Server Error", - error: ex, - }); + const errorMsg = "Internal Server Error"; + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/extensions/cactus-plugin-object-store-ipfs/src/main/typescript/web-services/get-object-endpoint-v1.ts b/extensions/cactus-plugin-object-store-ipfs/src/main/typescript/web-services/get-object-endpoint-v1.ts index 8f71e7c5f2..2f963f934b 100644 --- a/extensions/cactus-plugin-object-store-ipfs/src/main/typescript/web-services/get-object-endpoint-v1.ts +++ b/extensions/cactus-plugin-object-store-ipfs/src/main/typescript/web-services/get-object-endpoint-v1.ts @@ -16,7 +16,10 @@ import { IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import OAS from "../../json/openapi.json"; @@ -93,10 +96,8 @@ export class GetObjectEndpointV1 implements IWebServiceEndpoint { res.json(resBody); } catch (ex) { this.log.error(`${tag} Failed to serve request:`, ex); - res.status(500).json({ - message: "Internal Server Error", - error: ex, - }); + const errorMsg = "Internal Server Error"; + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/extensions/cactus-plugin-object-store-ipfs/src/main/typescript/web-services/has-object-endpoint-v1.ts b/extensions/cactus-plugin-object-store-ipfs/src/main/typescript/web-services/has-object-endpoint-v1.ts index 94998f2e99..2bfd49055d 100644 --- a/extensions/cactus-plugin-object-store-ipfs/src/main/typescript/web-services/has-object-endpoint-v1.ts +++ b/extensions/cactus-plugin-object-store-ipfs/src/main/typescript/web-services/has-object-endpoint-v1.ts @@ -16,7 +16,10 @@ import { IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import OAS from "../../json/openapi.json"; @@ -93,10 +96,8 @@ export class HasObjectEndpointV1 implements IWebServiceEndpoint { res.json(resBody); } catch (ex) { this.log.error(`${tag} Failed to serve request:`, ex); - res.status(500).json({ - message: "Internal Server Error", - error: ex, - }); + const errorMsg = "Internal Server Error"; + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/extensions/cactus-plugin-object-store-ipfs/src/main/typescript/web-services/set-object-endpoint-v1.ts b/extensions/cactus-plugin-object-store-ipfs/src/main/typescript/web-services/set-object-endpoint-v1.ts index fa05c36907..ca7bb3af9a 100644 --- a/extensions/cactus-plugin-object-store-ipfs/src/main/typescript/web-services/set-object-endpoint-v1.ts +++ b/extensions/cactus-plugin-object-store-ipfs/src/main/typescript/web-services/set-object-endpoint-v1.ts @@ -16,7 +16,10 @@ import { IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import OAS from "../../json/openapi.json"; @@ -93,10 +96,8 @@ export class SetObjectEndpointV1 implements IWebServiceEndpoint { res.json(resBody); } catch (ex) { this.log.error(`${tag} Failed to serve request:`, ex); - res.status(500).json({ - message: "Internal Server Error", - error: ex, - }); + const errorMsg = "Internal Server Error"; + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-api-client/src/test/typescript/integration/default-consortium-provider.test.ts b/packages/cactus-api-client/src/test/typescript/integration/default-consortium-provider.test.ts index 417d5254b9..3be869825d 100644 --- a/packages/cactus-api-client/src/test/typescript/integration/default-consortium-provider.test.ts +++ b/packages/cactus-api-client/src/test/typescript/integration/default-consortium-provider.test.ts @@ -32,18 +32,23 @@ test("Reports failures with meaningful information", async (t: Test) => { await provider.get(); t2.fail("Provider.get() did not throw despite API errors."); } catch (ex) { - if (typeof ex === 'object' && ex !== null) { - if ('message' in ex && typeof ex.message === 'string') { - t2.ok(ex, "Thrown error truthy OK"); - t2.ok(ex.message, "Thrown error.message truthy OK"); - t2.equal( - typeof ex.message, - "string", - "Thrown error.message type string OK", - ); - t2.true(ex.message.includes("timeout"), "Has timeout in msg OK"); - } - } else { t2.ok(ex, "Thrown error truthy OK"); } + if ( + typeof ex === "object" && + ex !== null && + "message" in ex && + typeof ex.message === "string" + ) { + t2.ok(ex, "Thrown error truthy OK"); + t2.ok(ex.message, "Thrown error.message truthy OK"); + t2.equal( + typeof ex.message, + "string", + "Thrown error.message type string OK", + ); + t2.true(ex.message.includes("timeout"), "Has timeout in msg OK"); + } else { + t2.ok(ex, "Thrown error truthy OK"); + } } t2.end(); }); @@ -61,9 +66,8 @@ test("Reports failures with meaningful information", async (t: Test) => { await provider.get(); t2.fail("Provider.get() did not throw despite API errors."); } catch (ex) { - - if (typeof ex === 'object' && ex !== null) { - if ('message' in ex && typeof ex.message === 'string') { + if (typeof ex === "object" && ex !== null) { + if ("message" in ex && typeof ex.message === "string") { t2.ok(ex, "Thrown error truthy OK"); t2.ok(ex.message, "Thrown error.message truthy OK"); t2.equal( @@ -76,8 +80,9 @@ test("Reports failures with meaningful information", async (t: Test) => { "Has Status Code in msg OK", ); } - } else { t2.ok(ex, "Thrown error truthy OK"); } - + } else { + t2.ok(ex, "Thrown error truthy OK"); + } } t2.end(); }); diff --git a/packages/cactus-cmd-api-server/src/main/typescript/web-services/watch-healthcheck-v1-endpoint.ts b/packages/cactus-cmd-api-server/src/main/typescript/web-services/watch-healthcheck-v1-endpoint.ts index a60035e92f..c56fe044ed 100644 --- a/packages/cactus-cmd-api-server/src/main/typescript/web-services/watch-healthcheck-v1-endpoint.ts +++ b/packages/cactus-cmd-api-server/src/main/typescript/web-services/watch-healthcheck-v1-endpoint.ts @@ -4,7 +4,6 @@ import { Logger, Checks } from "@hyperledger/cactus-common"; import { LogLevelDesc, LoggerProvider } from "@hyperledger/cactus-common"; import { HealthCheckResponse } from "../generated/openapi/typescript-axios"; import { WatchHealthcheckV1 } from "../generated/openapi/typescript-axios"; -import { response } from "express"; export interface IWatchHealthcheckV1EndpointOptions { logLevel?: LogLevelDesc; @@ -54,7 +53,7 @@ export class WatchHealthcheckV1Endpoint { socket.emit(WatchHealthcheckV1.Next, next); } catch (ex) { log.error(`Failed to construct health check response:`, ex); - let responseError = ex as HealthCheckResponse + const responseError = ex as HealthCheckResponse; socket.emit(WatchHealthcheckV1.Error, responseError); clearInterval(timerId); } diff --git a/packages/cactus-cmd-api-server/src/test/typescript/fixtures/plugin-ledger-connector-stub/web-services/deploy-contract-endpoint.ts b/packages/cactus-cmd-api-server/src/test/typescript/fixtures/plugin-ledger-connector-stub/web-services/deploy-contract-endpoint.ts index 56ca7e6b19..806d0374b5 100644 --- a/packages/cactus-cmd-api-server/src/test/typescript/fixtures/plugin-ledger-connector-stub/web-services/deploy-contract-endpoint.ts +++ b/packages/cactus-cmd-api-server/src/test/typescript/fixtures/plugin-ledger-connector-stub/web-services/deploy-contract-endpoint.ts @@ -12,10 +12,12 @@ import { LogLevelDesc, LoggerProvider, IAsyncProvider, - safeStringifyException, } from "@hyperledger/cactus-common"; -import { registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginLedgerConnectorStub } from "../plugin-ledger-connector-stub"; @@ -102,10 +104,8 @@ export class DeployContractEndpoint implements IWebServiceEndpoint { res.json(resBody); } catch (ex) { this.log.error(`Crash while serving ${reqTag}`, ex); - res.status(500).json({ - message: "Internal Server Error", - error: safeStringifyException(ex), - }); + const errorMsg = "Internal Server Error"; + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-cmd-api-server/src/test/typescript/fixtures/plugin-ledger-connector-stub/web-services/run-transaction-endpoint.ts b/packages/cactus-cmd-api-server/src/test/typescript/fixtures/plugin-ledger-connector-stub/web-services/run-transaction-endpoint.ts index ca1bed8c00..957ad943e1 100644 --- a/packages/cactus-cmd-api-server/src/test/typescript/fixtures/plugin-ledger-connector-stub/web-services/run-transaction-endpoint.ts +++ b/packages/cactus-cmd-api-server/src/test/typescript/fixtures/plugin-ledger-connector-stub/web-services/run-transaction-endpoint.ts @@ -6,14 +6,16 @@ import { LogLevelDesc, LoggerProvider, IAsyncProvider, - safeStringifyException, } from "@hyperledger/cactus-common"; import { IEndpointAuthzOptions, IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginLedgerConnectorStub } from "../plugin-ledger-connector-stub"; @@ -100,10 +102,8 @@ export class RunTransactionEndpoint implements IWebServiceEndpoint { res.json({ success: true, data: resBody }); } catch (ex) { this.log.error(`Crash while serving ${reqTag}`, ex); - res.status(500).json({ - message: "Internal Server Error", - error: safeStringifyException(ex), - }); + const errorMsg = "Internal Server Error"; + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-cmd-api-server/src/test/typescript/fixtures/plugin-ledger-connector-stub/web-services/unprotected-action-endpoint.ts b/packages/cactus-cmd-api-server/src/test/typescript/fixtures/plugin-ledger-connector-stub/web-services/unprotected-action-endpoint.ts index dbd693da78..4f6de7afeb 100644 --- a/packages/cactus-cmd-api-server/src/test/typescript/fixtures/plugin-ledger-connector-stub/web-services/unprotected-action-endpoint.ts +++ b/packages/cactus-cmd-api-server/src/test/typescript/fixtures/plugin-ledger-connector-stub/web-services/unprotected-action-endpoint.ts @@ -6,14 +6,16 @@ import { LogLevelDesc, LoggerProvider, IAsyncProvider, - safeStringifyException, } from "@hyperledger/cactus-common"; import { IEndpointAuthzOptions, IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginLedgerConnectorStub } from "../plugin-ledger-connector-stub"; @@ -106,10 +108,8 @@ export class UnprotectedActionEndpoint implements IWebServiceEndpoint { res.json({ success: true, data }); } catch (ex) { this.log.error(`Crash while serving ${reqTag}`, ex); - res.status(500).json({ - message: "Internal Server Error", - error: safeStringifyException(ex), - }); + const errorMsg = "Internal Server Error"; + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-cmd-socketio-server/src/main/typescript/routing-interface/routes/login.ts b/packages/cactus-cmd-socketio-server/src/main/typescript/routing-interface/routes/login.ts index fdd0f57fef..5dd5197889 100644 --- a/packages/cactus-cmd-socketio-server/src/main/typescript/routing-interface/routes/login.ts +++ b/packages/cactus-cmd-socketio-server/src/main/typescript/routing-interface/routes/login.ts @@ -46,11 +46,9 @@ router.post("/", (req: Request, res: Response, next: NextFunction) => { res.status(201); res.send(respData); } catch (err) { - - if (typeof err === 'object' && err !== null) { logger.error(`##err name: ${err.constructor.name}`); } - - - + if (typeof err === "object" && err !== null) { + logger.error(`##err name: ${err.constructor.name}`); + } if (err instanceof RIFError) { logger.debug(`##catch RIFError, ${err.statusCode}, ${err.message}`); diff --git a/packages/cactus-plugin-consortium-manual/src/main/typescript/consortium/get-consortium-jws-endpoint-v1.ts b/packages/cactus-plugin-consortium-manual/src/main/typescript/consortium/get-consortium-jws-endpoint-v1.ts index ae017298a1..8616f510ab 100644 --- a/packages/cactus-plugin-consortium-manual/src/main/typescript/consortium/get-consortium-jws-endpoint-v1.ts +++ b/packages/cactus-plugin-consortium-manual/src/main/typescript/consortium/get-consortium-jws-endpoint-v1.ts @@ -112,9 +112,7 @@ export class GetConsortiumEndpointV1 implements IWebServiceEndpoint { } catch (ex) { this.log.error(`${fnTag} failed to serve request`, ex); const errorMsg = `${fnTag} request handler fn crashed for: ${reqTag}`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) - - + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-consortium-manual/src/main/typescript/consortium/get-node-jws-endpoint-v1.ts b/packages/cactus-plugin-consortium-manual/src/main/typescript/consortium/get-node-jws-endpoint-v1.ts index a7d1c4f32e..0398ab4e58 100644 --- a/packages/cactus-plugin-consortium-manual/src/main/typescript/consortium/get-node-jws-endpoint-v1.ts +++ b/packages/cactus-plugin-consortium-manual/src/main/typescript/consortium/get-node-jws-endpoint-v1.ts @@ -108,7 +108,7 @@ export class GetNodeJwsEndpoint implements IWebServiceEndpoint { } catch (ex) { this.log.error(`${fnTag} failed to serve request`, ex); const errorMsg = `${fnTag} request handler fn crashed for: ${reqTag}`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-consortium-manual/src/main/typescript/consortium/get-prometheus-exporter-metrics-endpoint-v1.ts b/packages/cactus-plugin-consortium-manual/src/main/typescript/consortium/get-prometheus-exporter-metrics-endpoint-v1.ts index 497b69acb3..37b72b8e25 100644 --- a/packages/cactus-plugin-consortium-manual/src/main/typescript/consortium/get-prometheus-exporter-metrics-endpoint-v1.ts +++ b/packages/cactus-plugin-consortium-manual/src/main/typescript/consortium/get-prometheus-exporter-metrics-endpoint-v1.ts @@ -16,7 +16,10 @@ import { import OAS from "../../json/openapi.json"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginConsortiumManual } from "../plugin-consortium-manual"; @@ -26,7 +29,8 @@ export interface IGetPrometheusExporterMetricsEndpointV1Options { } export class GetPrometheusExporterMetricsEndpointV1 - implements IWebServiceEndpoint { + implements IWebServiceEndpoint +{ private readonly log: Logger; constructor( @@ -95,7 +99,7 @@ export class GetPrometheusExporterMetricsEndpointV1 } catch (ex) { this.log.error(`${fnTag} failed to serve request`, ex); const errorMsg = `${fnTag} request handler fn crashed for: ${reqTag}`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-htlc-eth-besu-erc20/src/main/typescript/web-services/get-single-status-endpoint.ts b/packages/cactus-plugin-htlc-eth-besu-erc20/src/main/typescript/web-services/get-single-status-endpoint.ts index d0d0adae8e..91f09ea100 100644 --- a/packages/cactus-plugin-htlc-eth-besu-erc20/src/main/typescript/web-services/get-single-status-endpoint.ts +++ b/packages/cactus-plugin-htlc-eth-besu-erc20/src/main/typescript/web-services/get-single-status-endpoint.ts @@ -11,7 +11,10 @@ import { IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import OAS from "../../json/openapi.json"; import { PluginHtlcEthBesuErc20 } from "../plugin-htlc-eth-besu-erc20"; @@ -86,7 +89,7 @@ export class GetSingleStatusEndpoint implements IWebServiceEndpoint { } catch (ex) { this.log.error(`${fnTag} failed to serve request`, ex); const errorMsg = `Bad request`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-htlc-eth-besu-erc20/src/main/typescript/web-services/get-status-endpoint.ts b/packages/cactus-plugin-htlc-eth-besu-erc20/src/main/typescript/web-services/get-status-endpoint.ts index de5849019f..3e8e563604 100644 --- a/packages/cactus-plugin-htlc-eth-besu-erc20/src/main/typescript/web-services/get-status-endpoint.ts +++ b/packages/cactus-plugin-htlc-eth-besu-erc20/src/main/typescript/web-services/get-status-endpoint.ts @@ -12,7 +12,10 @@ import { IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import OAS from "../../json/openapi.json"; import { PluginHtlcEthBesuErc20 } from "../plugin-htlc-eth-besu-erc20"; @@ -86,7 +89,7 @@ export class GetStatusEndpoint implements IWebServiceEndpoint { } catch (ex) { this.log.error(`${fnTag} failed to serve request`, ex); const errorMsg = `Bar request`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-htlc-eth-besu-erc20/src/main/typescript/web-services/initialize-endpoint.ts b/packages/cactus-plugin-htlc-eth-besu-erc20/src/main/typescript/web-services/initialize-endpoint.ts index f2938b30d0..7cdac1e4a4 100644 --- a/packages/cactus-plugin-htlc-eth-besu-erc20/src/main/typescript/web-services/initialize-endpoint.ts +++ b/packages/cactus-plugin-htlc-eth-besu-erc20/src/main/typescript/web-services/initialize-endpoint.ts @@ -12,7 +12,10 @@ import { IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import OAS from "../../json/openapi.json"; import { InitializeRequest } from "../generated/openapi/typescript-axios"; @@ -90,7 +93,7 @@ export class InitializeEndpoint implements IWebServiceEndpoint { } catch (ex) { this.log.error(`${fnTag} failed to serve request`, ex); const errorMsg = `Bad request`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-htlc-eth-besu-erc20/src/main/typescript/web-services/new-contract-endpoint.ts b/packages/cactus-plugin-htlc-eth-besu-erc20/src/main/typescript/web-services/new-contract-endpoint.ts index 84edffee57..91ba2c6f9a 100644 --- a/packages/cactus-plugin-htlc-eth-besu-erc20/src/main/typescript/web-services/new-contract-endpoint.ts +++ b/packages/cactus-plugin-htlc-eth-besu-erc20/src/main/typescript/web-services/new-contract-endpoint.ts @@ -11,7 +11,10 @@ import { IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { NewContractRequest } from "../generated/openapi/typescript-axios"; import OAS from "../../json/openapi.json"; import { PluginHtlcEthBesuErc20 } from "../plugin-htlc-eth-besu-erc20"; @@ -86,7 +89,7 @@ export class NewContractEndpoint implements IWebServiceEndpoint { } catch (ex) { this.log.error(`${fnTag} failed to serve request`, ex); const errorMsg = `Bad request`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-htlc-eth-besu-erc20/src/main/typescript/web-services/refund-endpoint.ts b/packages/cactus-plugin-htlc-eth-besu-erc20/src/main/typescript/web-services/refund-endpoint.ts index 5811385650..242da44d54 100644 --- a/packages/cactus-plugin-htlc-eth-besu-erc20/src/main/typescript/web-services/refund-endpoint.ts +++ b/packages/cactus-plugin-htlc-eth-besu-erc20/src/main/typescript/web-services/refund-endpoint.ts @@ -11,7 +11,10 @@ import { IWebServiceEndpoint, IEndpointAuthzOptions, } from "@hyperledger/cactus-core-api"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { RefundRequest } from "../generated/openapi/typescript-axios"; import OAS from "../../json/openapi.json"; import { PluginHtlcEthBesuErc20 } from "../plugin-htlc-eth-besu-erc20"; @@ -86,7 +89,7 @@ export class RefundEndpoint implements IWebServiceEndpoint { } catch (ex) { this.log.error(`${fnTag} failed to serve request`, ex); const errorMsg = `Bad request`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-htlc-eth-besu-erc20/src/main/typescript/web-services/withdraw-endpoint.ts b/packages/cactus-plugin-htlc-eth-besu-erc20/src/main/typescript/web-services/withdraw-endpoint.ts index 160c30b60d..fef65ae246 100644 --- a/packages/cactus-plugin-htlc-eth-besu-erc20/src/main/typescript/web-services/withdraw-endpoint.ts +++ b/packages/cactus-plugin-htlc-eth-besu-erc20/src/main/typescript/web-services/withdraw-endpoint.ts @@ -11,7 +11,10 @@ import { IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { WithdrawRequest } from "../generated/openapi/typescript-axios"; import OAS from "../../json/openapi.json"; import { PluginHtlcEthBesuErc20 } from "../plugin-htlc-eth-besu-erc20"; @@ -86,7 +89,7 @@ export class WithdrawEndpoint implements IWebServiceEndpoint { } catch (ex) { this.log.error(`${fnTag} failed to serve request`, ex); const errorMsg = `Bad request`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-htlc-eth-besu/src/main/typescript/web-services/get-single-status-endpoint.ts b/packages/cactus-plugin-htlc-eth-besu/src/main/typescript/web-services/get-single-status-endpoint.ts index eda2602f96..170520f849 100644 --- a/packages/cactus-plugin-htlc-eth-besu/src/main/typescript/web-services/get-single-status-endpoint.ts +++ b/packages/cactus-plugin-htlc-eth-besu/src/main/typescript/web-services/get-single-status-endpoint.ts @@ -11,7 +11,10 @@ import { IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginHtlcEthBesu } from "../plugin-htlc-eth-besu"; import OAS from "../../json/openapi.json"; @@ -94,7 +97,7 @@ export class GetSingleStatusEndpoint implements IWebServiceEndpoint { } catch (ex) { this.log.error(`${fnTag} failed to serve request`, ex); const errorMsg = `Internal server Error`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-htlc-eth-besu/src/main/typescript/web-services/get-status-endpoint.ts b/packages/cactus-plugin-htlc-eth-besu/src/main/typescript/web-services/get-status-endpoint.ts index 13d46f985f..e96dfe8344 100644 --- a/packages/cactus-plugin-htlc-eth-besu/src/main/typescript/web-services/get-status-endpoint.ts +++ b/packages/cactus-plugin-htlc-eth-besu/src/main/typescript/web-services/get-status-endpoint.ts @@ -11,7 +11,10 @@ import { IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import OAS from "../../json/openapi.json"; import { PluginHtlcEthBesu } from "../plugin-htlc-eth-besu"; export interface IGetStatusEndpointOptions { @@ -90,9 +93,9 @@ export class GetStatusEndpoint implements IWebServiceEndpoint { res.send(callOutput); } } catch (ex) { - this.log.error(`${fnTag} failed to serve request`, ex); + this.log.error(`${fnTag} request handler fn crashed for: ${reqTag}`, ex); const errorMsg = `Internal server error`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-htlc-eth-besu/src/main/typescript/web-services/initialize-endpoint.ts b/packages/cactus-plugin-htlc-eth-besu/src/main/typescript/web-services/initialize-endpoint.ts index 8c21ff11ee..c60b5f2ad7 100644 --- a/packages/cactus-plugin-htlc-eth-besu/src/main/typescript/web-services/initialize-endpoint.ts +++ b/packages/cactus-plugin-htlc-eth-besu/src/main/typescript/web-services/initialize-endpoint.ts @@ -11,7 +11,10 @@ import { IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import OAS from "../../json/openapi.json"; import { InitializeRequest } from "../generated/openapi/typescript-axios"; @@ -94,9 +97,9 @@ export class InitializeEndpoint implements IWebServiceEndpoint { res.send(result); } } catch (ex) { - this.log.error(`${fnTag} failed to serve request`, ex); + this.log.error(`${fnTag} request handler fn crashed for: ${reqTag}`, ex); const errorMsg = `Internal server Error`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-htlc-eth-besu/src/main/typescript/web-services/new-contract-endpoint.ts b/packages/cactus-plugin-htlc-eth-besu/src/main/typescript/web-services/new-contract-endpoint.ts index 4581afde9d..51b0b7d07e 100644 --- a/packages/cactus-plugin-htlc-eth-besu/src/main/typescript/web-services/new-contract-endpoint.ts +++ b/packages/cactus-plugin-htlc-eth-besu/src/main/typescript/web-services/new-contract-endpoint.ts @@ -11,7 +11,10 @@ import { IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { NewContractObj } from "../generated/openapi/typescript-axios/api"; import { PluginHtlcEthBesu } from "../plugin-htlc-eth-besu"; import OAS from "../../json/openapi.json"; @@ -92,9 +95,9 @@ export class NewContractEndpoint implements IWebServiceEndpoint { res.send(result); } } catch (ex) { - this.log.error(`${fnTag} failed to serve request`, ex); - const errorMsg = "Internal server Error" - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + this.log.error(`${fnTag} request handler fn crashed for: ${reqTag}`, ex); + const errorMsg = "Internal server Error"; + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-htlc-eth-besu/src/main/typescript/web-services/refund-endpoint.ts b/packages/cactus-plugin-htlc-eth-besu/src/main/typescript/web-services/refund-endpoint.ts index 021b47a677..34d11128aa 100644 --- a/packages/cactus-plugin-htlc-eth-besu/src/main/typescript/web-services/refund-endpoint.ts +++ b/packages/cactus-plugin-htlc-eth-besu/src/main/typescript/web-services/refund-endpoint.ts @@ -11,7 +11,10 @@ import { IWebServiceEndpoint, IEndpointAuthzOptions, } from "@hyperledger/cactus-core-api"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginHtlcEthBesu } from "../plugin-htlc-eth-besu"; import { RefundReq } from "../generated/openapi/typescript-axios"; import OAS from "../../json/openapi.json"; @@ -93,7 +96,7 @@ export class RefundEndpoint implements IWebServiceEndpoint { } catch (ex) { this.log.error(`${fnTag} failed to serve request`, ex); const errorMsg = "Internal server Error"; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-htlc-eth-besu/src/main/typescript/web-services/withdraw-endpoint.ts b/packages/cactus-plugin-htlc-eth-besu/src/main/typescript/web-services/withdraw-endpoint.ts index cfefba6e45..6608155a08 100644 --- a/packages/cactus-plugin-htlc-eth-besu/src/main/typescript/web-services/withdraw-endpoint.ts +++ b/packages/cactus-plugin-htlc-eth-besu/src/main/typescript/web-services/withdraw-endpoint.ts @@ -11,7 +11,10 @@ import { IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginHtlcEthBesu } from "../plugin-htlc-eth-besu"; import { WithdrawReq } from "../generated/openapi/typescript-axios/api"; import OAS from "../../json/openapi.json"; @@ -92,7 +95,7 @@ export class WithdrawEndpoint implements IWebServiceEndpoint { } catch (ex) { this.log.error(`${fnTag} failed to serve request`, ex); const errorMsg = `Internal server Error`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/delete-keychain-entry-endpoint-v1.ts b/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/delete-keychain-entry-endpoint-v1.ts index 9e43562c3b..fcd745a5dc 100644 --- a/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/delete-keychain-entry-endpoint-v1.ts +++ b/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/delete-keychain-entry-endpoint-v1.ts @@ -12,7 +12,10 @@ import { IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import OAS from "../../json/openapi.json"; import { PluginKeychainAwsSm } from "../plugin-keychain-aws-sm"; @@ -94,7 +97,7 @@ export class DeleteKeychainEntryV1Endpoint implements IWebServiceEndpoint { } catch (ex) { this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `Internal server Error`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/get-keychain-entry-endpoint-v1.ts b/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/get-keychain-entry-endpoint-v1.ts index 6a0a755b88..1195938b89 100644 --- a/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/get-keychain-entry-endpoint-v1.ts +++ b/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/get-keychain-entry-endpoint-v1.ts @@ -13,7 +13,10 @@ import { IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import OAS from "../../json/openapi.json"; import { PluginKeychainAwsSm } from "../plugin-keychain-aws-sm"; @@ -93,17 +96,30 @@ export class GetKeychainEntryV1Endpoint implements IWebServiceEndpoint { //const resBody = await this.options.connector.get(reqBody.key); res.json({ key, value }); } catch (ex) { - if (typeof ex === 'object' && ex !== null) { - if ('message' in ex && typeof ex.message === 'string') { - if (ex?.message?.includes(`${key} secret not found`)) { - const errorMsg = ex.message - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) - } + if ( + typeof ex === "object" && + ex !== null && + "message" in ex && + typeof ex.message === "string" + ) { + if (ex?.message?.includes(`${key} secret not found`)) { + const errorMsg = ex.message; + handleRestEndpointException({ + errorMsg, + log: this.log, + error: ex, + res, + }); } } else { this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `Internal server Error`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ + errorMsg, + log: this.log, + error: ex, + res, + }); } } } diff --git a/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/get-prometheus-exporter-metrics-endpoint-v1.ts b/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/get-prometheus-exporter-metrics-endpoint-v1.ts index 78baa5078a..a68cd92850 100644 --- a/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/get-prometheus-exporter-metrics-endpoint-v1.ts +++ b/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/get-prometheus-exporter-metrics-endpoint-v1.ts @@ -16,7 +16,10 @@ import { import OAS from "../../json/openapi.json"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginKeychainAwsSm } from "../plugin-keychain-aws-sm"; @@ -93,16 +96,28 @@ export class GetPrometheusExporterMetricsEndpointV1 res.send(resBody); } catch (ex) { this.log.error(`${fnTag} failed to serve request`, ex); - if (typeof ex === 'object' && ex !== null) { - if ('message' in ex && typeof ex.message === 'string') { - const errorMsg = ex.message - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) - } + if ( + typeof ex === "object" && + ex !== null && + "message" in ex && + typeof ex.message === "string" + ) { + const errorMsg = ex.message; + handleRestEndpointException({ + errorMsg, + log: this.log, + error: ex, + res, + }); } else { const errorMsg = `Bar request`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ + errorMsg, + log: this.log, + error: ex, + res, + }); } - } } } diff --git a/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/has-keychain-entry-endpoint-v1.ts b/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/has-keychain-entry-endpoint-v1.ts index be3013c9aa..27beb90d51 100644 --- a/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/has-keychain-entry-endpoint-v1.ts +++ b/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/has-keychain-entry-endpoint-v1.ts @@ -12,7 +12,10 @@ import { IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import OAS from "../../json/openapi.json"; import { PluginKeychainAwsSm } from "../plugin-keychain-aws-sm"; @@ -100,7 +103,7 @@ export class HasKeychainEntryV1Endpoint implements IWebServiceEndpoint { } catch (ex) { this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `Internal server Error}`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/set-keychain-entry-endpoint-v1.ts b/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/set-keychain-entry-endpoint-v1.ts index 18fa452f47..1ec082680d 100644 --- a/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/set-keychain-entry-endpoint-v1.ts +++ b/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/set-keychain-entry-endpoint-v1.ts @@ -12,7 +12,10 @@ import { IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import OAS from "../../json/openapi.json"; import { PluginKeychainAwsSm } from "../plugin-keychain-aws-sm"; @@ -93,7 +96,7 @@ export class SetKeychainEntryV1Endpoint implements IWebServiceEndpoint { } catch (ex) { this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `Internal server Error`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-keychain-azure-kv/src/main/typescript/web-services/delete-keychain-entry-endpoint.ts b/packages/cactus-plugin-keychain-azure-kv/src/main/typescript/web-services/delete-keychain-entry-endpoint.ts index a012b40650..7d82f85567 100644 --- a/packages/cactus-plugin-keychain-azure-kv/src/main/typescript/web-services/delete-keychain-entry-endpoint.ts +++ b/packages/cactus-plugin-keychain-azure-kv/src/main/typescript/web-services/delete-keychain-entry-endpoint.ts @@ -12,7 +12,10 @@ import { IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginKeychainAzureKv } from "../plugin-keychain-azure-kv"; @@ -94,7 +97,7 @@ export class DeleteKeychainEntryEndpoint implements IWebServiceEndpoint { } catch (ex) { this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `Internal server Error`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-keychain-azure-kv/src/main/typescript/web-services/get-keychain-entry-endpoint.ts b/packages/cactus-plugin-keychain-azure-kv/src/main/typescript/web-services/get-keychain-entry-endpoint.ts index 7f556a20fe..ff6dc4fc45 100644 --- a/packages/cactus-plugin-keychain-azure-kv/src/main/typescript/web-services/get-keychain-entry-endpoint.ts +++ b/packages/cactus-plugin-keychain-azure-kv/src/main/typescript/web-services/get-keychain-entry-endpoint.ts @@ -12,7 +12,10 @@ import { IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginKeychainAzureKv } from "../plugin-keychain-azure-kv"; @@ -95,17 +98,29 @@ export class GetKeychainEntryEndpoint implements IWebServiceEndpoint { value, }); } catch (ex) { - if (typeof ex === 'object' && ex !== null) { - if ('message' in ex && typeof ex.message === 'string') { - if (ex?.message?.includes(`${key} secret not found`)) { - const errorMsg = ex.message - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) - } - } + if ( + typeof ex === "object" && + ex !== null && + "message" in ex && + typeof ex.message === "string" && + ex?.message?.includes(`${key} secret not found`) + ) { + const errorMsg = ex.message; + handleRestEndpointException({ + errorMsg, + log: this.log, + error: ex, + res, + }); } else { this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `Internal server Error`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ + errorMsg, + log: this.log, + error: ex, + res, + }); } } } diff --git a/packages/cactus-plugin-keychain-azure-kv/src/main/typescript/web-services/has-keychain-entry-endpoint.ts b/packages/cactus-plugin-keychain-azure-kv/src/main/typescript/web-services/has-keychain-entry-endpoint.ts index 287e9337d7..65f19b9c32 100644 --- a/packages/cactus-plugin-keychain-azure-kv/src/main/typescript/web-services/has-keychain-entry-endpoint.ts +++ b/packages/cactus-plugin-keychain-azure-kv/src/main/typescript/web-services/has-keychain-entry-endpoint.ts @@ -14,7 +14,10 @@ import { IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginKeychainAzureKv } from "../plugin-keychain-azure-kv"; @@ -102,7 +105,7 @@ export class HasKeychainEntryEndpoint implements IWebServiceEndpoint { } catch (ex) { this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `Internal server Error`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-keychain-azure-kv/src/main/typescript/web-services/set-keychain-entry-endpoint.ts b/packages/cactus-plugin-keychain-azure-kv/src/main/typescript/web-services/set-keychain-entry-endpoint.ts index 7fbfc830e0..a979af230d 100644 --- a/packages/cactus-plugin-keychain-azure-kv/src/main/typescript/web-services/set-keychain-entry-endpoint.ts +++ b/packages/cactus-plugin-keychain-azure-kv/src/main/typescript/web-services/set-keychain-entry-endpoint.ts @@ -12,7 +12,10 @@ import { IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginKeychainAzureKv } from "../plugin-keychain-azure-kv"; @@ -94,7 +97,7 @@ export class SetKeychainEntryEndpoint implements IWebServiceEndpoint { } catch (ex) { this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `Internal server Error`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-keychain-google-sm/src/main/typescript/webservices/delete-keychain-entry-endpoint-v1.ts b/packages/cactus-plugin-keychain-google-sm/src/main/typescript/webservices/delete-keychain-entry-endpoint-v1.ts index 6053028f7d..20e00f5bf3 100644 --- a/packages/cactus-plugin-keychain-google-sm/src/main/typescript/webservices/delete-keychain-entry-endpoint-v1.ts +++ b/packages/cactus-plugin-keychain-google-sm/src/main/typescript/webservices/delete-keychain-entry-endpoint-v1.ts @@ -12,7 +12,10 @@ import { IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import OAS from "../../json/openapi.json"; import { PluginKeychainGoogleSm } from "../plugin-keychain-google-sm"; @@ -92,7 +95,7 @@ export class DeleteKeychainEntryV1Endpoint implements IWebServiceEndpoint { } catch (ex) { this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `Internal server Error`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-keychain-google-sm/src/main/typescript/webservices/get-keychain-entry-endpoint-v1.ts b/packages/cactus-plugin-keychain-google-sm/src/main/typescript/webservices/get-keychain-entry-endpoint-v1.ts index 04225a2a79..b61faaa4c7 100644 --- a/packages/cactus-plugin-keychain-google-sm/src/main/typescript/webservices/get-keychain-entry-endpoint-v1.ts +++ b/packages/cactus-plugin-keychain-google-sm/src/main/typescript/webservices/get-keychain-entry-endpoint-v1.ts @@ -12,7 +12,10 @@ import { IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import OAS from "../../json/openapi.json"; import { PluginKeychainGoogleSm } from "../plugin-keychain-google-sm"; @@ -90,16 +93,29 @@ export class GetKeychainEntryV1Endpoint implements IWebServiceEndpoint { const resBody = await this.options.connector.get(reqBody.key); res.json(resBody); } catch (ex) { - if (typeof ex === 'object' && ex !== null) { - if ('message' in ex && ex['message'] && typeof ex.message === 'string') { - const errorMsg = ex.message - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) - } - } - else { + if ( + typeof ex === "object" && + ex !== null && + "message" in ex && + ex["message"] && + typeof ex.message === "string" + ) { + const errorMsg = ex.message; + handleRestEndpointException({ + errorMsg, + log: this.log, + error: ex, + res, + }); + } else { this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `Internal server Error`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ + errorMsg, + log: this.log, + error: ex, + res, + }); } } } diff --git a/packages/cactus-plugin-keychain-google-sm/src/main/typescript/webservices/has-keychain-entry-endpoint-v1.ts b/packages/cactus-plugin-keychain-google-sm/src/main/typescript/webservices/has-keychain-entry-endpoint-v1.ts index bf417e3c4c..1410bfc671 100644 --- a/packages/cactus-plugin-keychain-google-sm/src/main/typescript/webservices/has-keychain-entry-endpoint-v1.ts +++ b/packages/cactus-plugin-keychain-google-sm/src/main/typescript/webservices/has-keychain-entry-endpoint-v1.ts @@ -12,7 +12,10 @@ import { IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import OAS from "../../json/openapi.json"; import { PluginKeychainGoogleSm } from "../plugin-keychain-google-sm"; @@ -94,7 +97,7 @@ export class HasKeychainEntryV1Endpoint implements IWebServiceEndpoint { } catch (ex) { this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `Internal server Error`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-keychain-google-sm/src/main/typescript/webservices/set-keychain-entry-endpoint-v1.ts b/packages/cactus-plugin-keychain-google-sm/src/main/typescript/webservices/set-keychain-entry-endpoint-v1.ts index 8eed0229f8..2d95bde825 100644 --- a/packages/cactus-plugin-keychain-google-sm/src/main/typescript/webservices/set-keychain-entry-endpoint-v1.ts +++ b/packages/cactus-plugin-keychain-google-sm/src/main/typescript/webservices/set-keychain-entry-endpoint-v1.ts @@ -12,7 +12,10 @@ import { IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import OAS from "../../json/openapi.json"; import { PluginKeychainGoogleSm } from "../plugin-keychain-google-sm"; @@ -94,8 +97,8 @@ export class SetKeychainEntryV1Endpoint implements IWebServiceEndpoint { res.json(resBody); } catch (ex) { this.log.error(`Crash while serving ${reqTag}`, ex); - const errorMsg = `Internal server Erorr`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + const errorMsg = `Internal server Error`; + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-keychain-google-sm/src/test/typescript/integration/openapi/openapi-validation.test.ts b/packages/cactus-plugin-keychain-google-sm/src/test/typescript/integration/openapi/openapi-validation.test.ts index d89b12a909..fb7683444d 100644 --- a/packages/cactus-plugin-keychain-google-sm/src/test/typescript/integration/openapi/openapi-validation.test.ts +++ b/packages/cactus-plugin-keychain-google-sm/src/test/typescript/integration/openapi/openapi-validation.test.ts @@ -114,7 +114,7 @@ test(testCase, async (t: Test) => { value, } as any as SetKeychainEntryRequestV1); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, @@ -134,7 +134,7 @@ test(testCase, async (t: Test) => { {} as any as GetKeychainEntryRequestV1, ); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, @@ -154,7 +154,7 @@ test(testCase, async (t: Test) => { {} as any as HasKeychainEntryRequestV1, ); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, @@ -174,7 +174,7 @@ test(testCase, async (t: Test) => { {} as any as DeleteKeychainEntryRequestV1, ); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, @@ -196,7 +196,7 @@ test(testCase, async (t: Test) => { fake: 4, } as any as SetKeychainEntryRequestV1); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, @@ -220,7 +220,7 @@ test(testCase, async (t: Test) => { fake: 4, } as any as GetKeychainEntryRequestV1); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, @@ -244,7 +244,7 @@ test(testCase, async (t: Test) => { fake: 4, } as any as HasKeychainEntryRequestV1); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, @@ -268,7 +268,7 @@ test(testCase, async (t: Test) => { fake: 4, } as any as DeleteKeychainEntryRequestV1); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, diff --git a/packages/cactus-plugin-keychain-memory-wasm/src/main/typescript/webservices/delete-keychain-entry-endpoint-v1.ts b/packages/cactus-plugin-keychain-memory-wasm/src/main/typescript/webservices/delete-keychain-entry-endpoint-v1.ts index 783b9d2984..c29191c1d6 100644 --- a/packages/cactus-plugin-keychain-memory-wasm/src/main/typescript/webservices/delete-keychain-entry-endpoint-v1.ts +++ b/packages/cactus-plugin-keychain-memory-wasm/src/main/typescript/webservices/delete-keychain-entry-endpoint-v1.ts @@ -12,7 +12,10 @@ import { IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { DeleteKeychainEntryRequestV1 } from "@hyperledger/cactus-core-api"; import OAS from "../../json/openapi.json"; @@ -93,7 +96,7 @@ export class DeleteKeychainEntryV1Endpoint implements IWebServiceEndpoint { } catch (ex) { this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `Internal server Error`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-keychain-memory-wasm/src/main/typescript/webservices/get-keychain-entry-endpoint-v1.ts b/packages/cactus-plugin-keychain-memory-wasm/src/main/typescript/webservices/get-keychain-entry-endpoint-v1.ts index 2ec2b93226..1a2f2de623 100644 --- a/packages/cactus-plugin-keychain-memory-wasm/src/main/typescript/webservices/get-keychain-entry-endpoint-v1.ts +++ b/packages/cactus-plugin-keychain-memory-wasm/src/main/typescript/webservices/get-keychain-entry-endpoint-v1.ts @@ -13,7 +13,10 @@ import { IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import OAS from "../../json/openapi.json"; import { PluginKeychainMemoryWasm } from "../plugin-keychain-memory-wasm"; @@ -91,16 +94,29 @@ export class GetKeychainEntryV1Endpoint implements IWebServiceEndpoint { const value = await this.options.plugin.get(key); res.json({ key, value }); } catch (ex) { - if (typeof ex === 'object' && ex !== null) { - if ('message' in ex && ex['message'] && typeof ex.message === 'string') { - const errorMsg = ex.message - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) - } - + if ( + typeof ex === "object" && + ex !== null && + "message" in ex && + ex["message"] && + typeof ex.message === "string" + ) { + const errorMsg = ex.message; + handleRestEndpointException({ + errorMsg, + log: this.log, + error: ex, + res, + }); } else { this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `Internal server Error`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ + errorMsg, + log: this.log, + error: ex, + res, + }); } } } diff --git a/packages/cactus-plugin-keychain-memory-wasm/src/main/typescript/webservices/has-keychain-entry-endpoint-v1.ts b/packages/cactus-plugin-keychain-memory-wasm/src/main/typescript/webservices/has-keychain-entry-endpoint-v1.ts index c649dd3c37..394a7bfdcb 100644 --- a/packages/cactus-plugin-keychain-memory-wasm/src/main/typescript/webservices/has-keychain-entry-endpoint-v1.ts +++ b/packages/cactus-plugin-keychain-memory-wasm/src/main/typescript/webservices/has-keychain-entry-endpoint-v1.ts @@ -12,7 +12,10 @@ import { IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import OAS from "../../json/openapi.json"; import { PluginKeychainMemoryWasm } from "../plugin-keychain-memory-wasm"; @@ -100,7 +103,7 @@ export class HasKeychainEntryV1Endpoint implements IWebServiceEndpoint { } catch (ex) { this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `Internal server Error`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-keychain-memory-wasm/src/main/typescript/webservices/set-keychain-entry-endpoint-v1.ts b/packages/cactus-plugin-keychain-memory-wasm/src/main/typescript/webservices/set-keychain-entry-endpoint-v1.ts index 61ec64dad1..eda27080b8 100644 --- a/packages/cactus-plugin-keychain-memory-wasm/src/main/typescript/webservices/set-keychain-entry-endpoint-v1.ts +++ b/packages/cactus-plugin-keychain-memory-wasm/src/main/typescript/webservices/set-keychain-entry-endpoint-v1.ts @@ -12,7 +12,10 @@ import { IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import OAS from "../../json/openapi.json"; import { PluginKeychainMemoryWasm } from "../plugin-keychain-memory-wasm"; @@ -93,7 +96,7 @@ export class SetKeychainEntryV1Endpoint implements IWebServiceEndpoint { } catch (ex) { this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `Internal server Error`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-keychain-memory/src/main/typescript/get-prometheus-exporter-metrics/get-prometheus-exporter-metrics-endpoint-v1.ts b/packages/cactus-plugin-keychain-memory/src/main/typescript/get-prometheus-exporter-metrics/get-prometheus-exporter-metrics-endpoint-v1.ts index d745e6e789..c3d041bc30 100644 --- a/packages/cactus-plugin-keychain-memory/src/main/typescript/get-prometheus-exporter-metrics/get-prometheus-exporter-metrics-endpoint-v1.ts +++ b/packages/cactus-plugin-keychain-memory/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 { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginKeychainMemory } from "../plugin-keychain-memory"; @@ -26,7 +29,8 @@ export interface IGetPrometheusExporterMetricsEndpointV1Options { } export class GetPrometheusExporterMetricsEndpointV1 - implements IWebServiceEndpoint { + implements IWebServiceEndpoint +{ private readonly log: Logger; constructor( @@ -83,7 +87,6 @@ export class GetPrometheusExporterMetricsEndpointV1 } async handleRequest(req: Request, res: Response): Promise { - const fnTag = "GetPrometheusExporterMetrics#handleRequest()"; const verbUpper = this.getVerbLowerCase().toUpperCase(); this.log.debug(`${verbUpper} ${this.getPath()}`); @@ -92,14 +95,28 @@ export class GetPrometheusExporterMetricsEndpointV1 res.status(200); res.send(resBody); } catch (ex) { - if (typeof ex === 'object' && ex !== null) { - if ('message' in ex && ex['message'] && typeof ex.message === 'string') { - const errorMsg = ex.message - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) - } + if ( + typeof ex === "object" && + ex !== null && + "message" in ex && + ex["message"] && + typeof ex.message === "string" + ) { + const errorMsg = ex.message; + handleRestEndpointException({ + errorMsg, + log: this.log, + error: ex, + res, + }); } else { - const errorMsg = '' - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + const errorMsg = ""; + handleRestEndpointException({ + errorMsg, + log: this.log, + error: ex, + res, + }); } } } diff --git a/packages/cactus-plugin-keychain-vault/src/main/typescript/plugin-keychain-vault.ts b/packages/cactus-plugin-keychain-vault/src/main/typescript/plugin-keychain-vault.ts index 3ec4b5712e..ca3699f67d 100644 --- a/packages/cactus-plugin-keychain-vault/src/main/typescript/plugin-keychain-vault.ts +++ b/packages/cactus-plugin-keychain-vault/src/main/typescript/plugin-keychain-vault.ts @@ -1,7 +1,7 @@ import type { Express } from "express"; import Vault from "node-vault"; import HttpStatus from "http-status-codes"; -import handleVaultResponse from "node-vault" +import handleVaultResponse from "node-vault"; import OAS from "../json/openapi.json"; import { @@ -255,10 +255,11 @@ export class PluginKeychainVault implements IPluginWebService, IPluginKeychain { const path = this.pathFor(key); try { const res = await this.backend.read(path); - return res; `` + return res; + ``; } catch (ex) { const errorResponse = ex as ErrorResponse; - handleVaultResponse() + handleVaultResponse(); // We have to make sure that the exception is either an expected // or an unexpected one where the expected exception is `what we // get when the key is not present in the keychain and anything diff --git a/packages/cactus-plugin-keychain-vault/src/main/typescript/web-services/delete-keychain-entry-endpoint-v1.ts b/packages/cactus-plugin-keychain-vault/src/main/typescript/web-services/delete-keychain-entry-endpoint-v1.ts index 28da671dd7..7c6f46d68a 100644 --- a/packages/cactus-plugin-keychain-vault/src/main/typescript/web-services/delete-keychain-entry-endpoint-v1.ts +++ b/packages/cactus-plugin-keychain-vault/src/main/typescript/web-services/delete-keychain-entry-endpoint-v1.ts @@ -12,7 +12,10 @@ import { IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import OAS from "../../json/openapi.json"; import { PluginKeychainVault } from "../plugin-keychain-vault"; @@ -103,7 +106,7 @@ export class DeleteKeychainEntryEndpointV1 implements IWebServiceEndpoint { this.log.debug(`${tag} Failed to serve request:`, ex); res.status(500); const errorMsg = `Internal server Error`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-keychain-vault/src/main/typescript/web-services/get-keychain-entry-endpoint-v1.ts b/packages/cactus-plugin-keychain-vault/src/main/typescript/web-services/get-keychain-entry-endpoint-v1.ts index 17f136545f..fd713625b8 100644 --- a/packages/cactus-plugin-keychain-vault/src/main/typescript/web-services/get-keychain-entry-endpoint-v1.ts +++ b/packages/cactus-plugin-keychain-vault/src/main/typescript/web-services/get-keychain-entry-endpoint-v1.ts @@ -12,7 +12,10 @@ import { IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import OAS from "../../json/openapi.json"; import { PluginKeychainVault } from "../plugin-keychain-vault"; @@ -103,7 +106,7 @@ export class GetKeychainEntryEndpointV1 implements IWebServiceEndpoint { } catch (ex) { this.log.debug(`${tag} Failed to serve request:`, ex); const errorMsg = `Internal server Error`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-keychain-vault/src/main/typescript/web-services/get-prometheus-exporter-metrics-endpoint-v1.ts b/packages/cactus-plugin-keychain-vault/src/main/typescript/web-services/get-prometheus-exporter-metrics-endpoint-v1.ts index 82d9a949b4..db0c807117 100644 --- a/packages/cactus-plugin-keychain-vault/src/main/typescript/web-services/get-prometheus-exporter-metrics-endpoint-v1.ts +++ b/packages/cactus-plugin-keychain-vault/src/main/typescript/web-services/get-prometheus-exporter-metrics-endpoint-v1.ts @@ -16,7 +16,10 @@ import { import OAS from "../../json/openapi.json"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginKeychainVault } from "../plugin-keychain-vault"; @@ -26,7 +29,8 @@ export interface IGetPrometheusExporterMetricsEndpointV1Options { } export class GetPrometheusExporterMetricsEndpointV1 - implements IWebServiceEndpoint { + implements IWebServiceEndpoint +{ private readonly log: Logger; constructor( @@ -94,7 +98,7 @@ export class GetPrometheusExporterMetricsEndpointV1 } catch (ex) { this.log.error(`${fnTag} failed to serve request`, ex); const errorMsg = `Internal server Error`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-keychain-vault/src/main/typescript/web-services/has-keychain-entry-endpoint-v1.ts b/packages/cactus-plugin-keychain-vault/src/main/typescript/web-services/has-keychain-entry-endpoint-v1.ts index d8e4b7b2c8..b9e14d7af5 100644 --- a/packages/cactus-plugin-keychain-vault/src/main/typescript/web-services/has-keychain-entry-endpoint-v1.ts +++ b/packages/cactus-plugin-keychain-vault/src/main/typescript/web-services/has-keychain-entry-endpoint-v1.ts @@ -12,7 +12,10 @@ import { IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import OAS from "../../json/openapi.json"; import { PluginKeychainVault } from "../plugin-keychain-vault"; @@ -104,7 +107,7 @@ export class HasKeychainEntryEndpointV1 implements IWebServiceEndpoint { } catch (ex) { this.log.debug(`${tag} Failed to serve request:`, ex); const errorMsg = `Internal server Error`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-keychain-vault/src/main/typescript/web-services/set-keychain-entry-endpoint-v1.ts b/packages/cactus-plugin-keychain-vault/src/main/typescript/web-services/set-keychain-entry-endpoint-v1.ts index cfd1cd681d..acc2de7005 100644 --- a/packages/cactus-plugin-keychain-vault/src/main/typescript/web-services/set-keychain-entry-endpoint-v1.ts +++ b/packages/cactus-plugin-keychain-vault/src/main/typescript/web-services/set-keychain-entry-endpoint-v1.ts @@ -12,7 +12,10 @@ import { IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import OAS from "../../json/openapi.json"; import { PluginKeychainVault } from "../plugin-keychain-vault"; @@ -98,7 +101,7 @@ export class SetKeychainEntryEndpointV1 implements IWebServiceEndpoint { } catch (ex) { this.log.debug(`${tag} Failed to serve request:`, ex); const errorMsg = `Internal server Error`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-ledger-connector-aries/src/main/typescript/web-services/accept-invitation-v1-endpoint.ts b/packages/cactus-plugin-ledger-connector-aries/src/main/typescript/web-services/accept-invitation-v1-endpoint.ts index 123d8edc18..7864275587 100644 --- a/packages/cactus-plugin-ledger-connector-aries/src/main/typescript/web-services/accept-invitation-v1-endpoint.ts +++ b/packages/cactus-plugin-ledger-connector-aries/src/main/typescript/web-services/accept-invitation-v1-endpoint.ts @@ -11,9 +11,11 @@ import { LogLevelDesc, LoggerProvider, IAsyncProvider, - safeStringifyException, } from "@hyperledger/cactus-common"; -import { registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginLedgerConnectorAries } from "../plugin-ledger-connector-aries"; import OAS from "../../json/openapi.json"; @@ -93,11 +95,8 @@ export class AcceptInvitationEndpoint implements IWebServiceEndpoint { ); } catch (ex) { this.log.error(`Crash while serving ${reqTag}`, ex); - - res.status(500).json({ - message: "Internal Server Error", - error: safeStringifyException(ex), - }); + const errorMsg = "Internal Server Error"; + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-ledger-connector-aries/src/main/typescript/web-services/create-new-connection-invitation-v1-endpoint.ts b/packages/cactus-plugin-ledger-connector-aries/src/main/typescript/web-services/create-new-connection-invitation-v1-endpoint.ts index f2805929bf..bf023ad58a 100644 --- a/packages/cactus-plugin-ledger-connector-aries/src/main/typescript/web-services/create-new-connection-invitation-v1-endpoint.ts +++ b/packages/cactus-plugin-ledger-connector-aries/src/main/typescript/web-services/create-new-connection-invitation-v1-endpoint.ts @@ -11,9 +11,11 @@ import { LogLevelDesc, LoggerProvider, IAsyncProvider, - safeStringifyException, } from "@hyperledger/cactus-common"; -import { registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginLedgerConnectorAries } from "../plugin-ledger-connector-aries"; import OAS from "../../json/openapi.json"; @@ -24,8 +26,7 @@ export interface ICreateNewConnectionInvitationOptions { } export class CreateNewConnectionInvitationEndpoint - implements IWebServiceEndpoint -{ + implements IWebServiceEndpoint { private readonly log: Logger; public get className(): string { @@ -95,11 +96,8 @@ export class CreateNewConnectionInvitationEndpoint ); } catch (ex) { this.log.error(`Crash while serving ${reqTag}`, ex); - - res.status(500).json({ - message: "Internal Server Error", - error: safeStringifyException(ex), - }); + const errorMsg = "Internal Server Error"; + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-ledger-connector-aries/src/main/typescript/web-services/get-agents-v1-endpoint.ts b/packages/cactus-plugin-ledger-connector-aries/src/main/typescript/web-services/get-agents-v1-endpoint.ts index 5d896b8354..7ae22cccc7 100644 --- a/packages/cactus-plugin-ledger-connector-aries/src/main/typescript/web-services/get-agents-v1-endpoint.ts +++ b/packages/cactus-plugin-ledger-connector-aries/src/main/typescript/web-services/get-agents-v1-endpoint.ts @@ -11,9 +11,11 @@ import { LogLevelDesc, LoggerProvider, IAsyncProvider, - safeStringifyException, } from "@hyperledger/cactus-common"; -import { registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginLedgerConnectorAries } from "../plugin-ledger-connector-aries"; import OAS from "../../json/openapi.json"; @@ -86,11 +88,8 @@ export class GetAgentsEndpoint implements IWebServiceEndpoint { res.status(200).json(await this.options.connector.getAgents()); } catch (ex) { this.log.error(`Crash while serving ${reqTag}`, ex); - - res.status(500).json({ - message: "Internal Server Error", - error: safeStringifyException(ex), - }); + const errorMsg = "Internal Server Error"; + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-ledger-connector-aries/src/main/typescript/web-services/get-connections-v1-endpoint.ts b/packages/cactus-plugin-ledger-connector-aries/src/main/typescript/web-services/get-connections-v1-endpoint.ts index bd23474054..d37da3540a 100644 --- a/packages/cactus-plugin-ledger-connector-aries/src/main/typescript/web-services/get-connections-v1-endpoint.ts +++ b/packages/cactus-plugin-ledger-connector-aries/src/main/typescript/web-services/get-connections-v1-endpoint.ts @@ -11,9 +11,11 @@ import { LogLevelDesc, LoggerProvider, IAsyncProvider, - safeStringifyException, } from "@hyperledger/cactus-common"; -import { registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginLedgerConnectorAries } from "../plugin-ledger-connector-aries"; import OAS from "../../json/openapi.json"; @@ -93,11 +95,8 @@ export class GetConnectionsEndpoint implements IWebServiceEndpoint { ); } catch (ex) { this.log.error(`Crash while serving ${reqTag}`, ex); - - res.status(500).json({ - message: "Internal Server Error", - error: safeStringifyException(ex), - }); + const errorMsg = "Internal Server Error"; + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-ledger-connector-aries/src/main/typescript/web-services/request-proof-v1-endpoint.ts b/packages/cactus-plugin-ledger-connector-aries/src/main/typescript/web-services/request-proof-v1-endpoint.ts index 948e894ec2..c4c834da5f 100644 --- a/packages/cactus-plugin-ledger-connector-aries/src/main/typescript/web-services/request-proof-v1-endpoint.ts +++ b/packages/cactus-plugin-ledger-connector-aries/src/main/typescript/web-services/request-proof-v1-endpoint.ts @@ -11,9 +11,11 @@ import { LogLevelDesc, LoggerProvider, IAsyncProvider, - safeStringifyException, } from "@hyperledger/cactus-common"; -import { registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginLedgerConnectorAries } from "../plugin-ledger-connector-aries"; import OAS from "../../json/openapi.json"; @@ -94,11 +96,8 @@ export class RequestProofEndpoint implements IWebServiceEndpoint { ); } catch (ex) { this.log.error(`Crash while serving ${reqTag}`, ex); - - res.status(500).json({ - message: "Internal Server Error", - error: safeStringifyException(ex), - }); + const errorMsg = "Internal Server Error"; + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/get-balance-endpoint.ts b/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/get-balance-endpoint.ts index ce391e5176..3ee2616d6e 100644 --- a/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/get-balance-endpoint.ts +++ b/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/get-balance-endpoint.ts @@ -12,7 +12,10 @@ import { IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginLedgerConnectorBesu } from "../plugin-ledger-connector-besu"; @@ -91,7 +94,7 @@ export class GetBalanceEndpoint implements IWebServiceEndpoint { } catch (ex) { this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `Internal server Error`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/get-besu-record-endpoint-v1.ts b/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/get-besu-record-endpoint-v1.ts index 695354990a..8a68fa6503 100644 --- a/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/get-besu-record-endpoint-v1.ts +++ b/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/get-besu-record-endpoint-v1.ts @@ -12,7 +12,10 @@ import { IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginLedgerConnectorBesu } from "../plugin-ledger-connector-besu"; import { GetBesuRecordV1Request } from "../generated/openapi/typescript-axios/api"; @@ -95,7 +98,7 @@ export class GetBesuRecordEndpointV1 implements IWebServiceEndpoint { } catch (ex) { this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `Internal server Error`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/get-block-v1-endpoint-.ts b/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/get-block-v1-endpoint-.ts index 93d4fc0fc4..192184443b 100644 --- a/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/get-block-v1-endpoint-.ts +++ b/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/get-block-v1-endpoint-.ts @@ -12,7 +12,10 @@ import { IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginLedgerConnectorBesu } from "../plugin-ledger-connector-besu"; @@ -91,7 +94,7 @@ export class GetBlockEndpoint implements IWebServiceEndpoint { } catch (ex) { this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `Internal server Error`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/get-past-logs-endpoint.ts b/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/get-past-logs-endpoint.ts index b200800c67..68c0590ab0 100644 --- a/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/get-past-logs-endpoint.ts +++ b/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/get-past-logs-endpoint.ts @@ -12,7 +12,10 @@ import { IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginLedgerConnectorBesu } from "../plugin-ledger-connector-besu"; @@ -91,7 +94,7 @@ export class GetPastLogsEndpoint implements IWebServiceEndpoint { } catch (ex) { this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `Internal server Error`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/get-prometheus-exporter-metrics-endpoint-v1.ts b/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/get-prometheus-exporter-metrics-endpoint-v1.ts index 151a3ad738..c192ec2deb 100644 --- a/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/get-prometheus-exporter-metrics-endpoint-v1.ts +++ b/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/get-prometheus-exporter-metrics-endpoint-v1.ts @@ -1,6 +1,9 @@ import { Express, Request, Response } from "express"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import OAS from "../../json/openapi.json"; @@ -94,16 +97,28 @@ export class GetPrometheusExporterMetricsEndpointV1 res.send(resBody); } catch (ex) { this.log.error(`${fnTag} failed to serve request`, ex); - if (typeof ex === 'object' && ex !== null) { - if ('message' in ex && typeof ex.message === 'string') { - const errorMsg = ex.message - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) - } - } - else { + if ( + typeof ex === "object" && + ex !== null && + "message" in ex && + typeof ex.message === "string" + ) { + const errorMsg = ex.message; + handleRestEndpointException({ + errorMsg, + log: this.log, + error: ex, + res, + }); + } else { this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `Internal server Error`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ + errorMsg, + log: this.log, + error: ex, + res, + }); } } } diff --git a/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/get-transaction-endpoint.ts b/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/get-transaction-endpoint.ts index 818b72e97a..78a78f3ac7 100644 --- a/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/get-transaction-endpoint.ts +++ b/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/get-transaction-endpoint.ts @@ -12,7 +12,10 @@ import { IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginLedgerConnectorBesu } from "../plugin-ledger-connector-besu"; @@ -92,7 +95,7 @@ export class GetTransactionEndpoint implements IWebServiceEndpoint { this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `Internal server Error`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/invoke-contract-endpoint.ts b/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/invoke-contract-endpoint.ts index 7c3749408a..656f915e31 100644 --- a/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/invoke-contract-endpoint.ts +++ b/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/invoke-contract-endpoint.ts @@ -12,7 +12,10 @@ import { IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginLedgerConnectorBesu } from "../plugin-ledger-connector-besu"; @@ -92,7 +95,7 @@ export class InvokeContractEndpoint implements IWebServiceEndpoint { } catch (ex) { this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `Internal server Error`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/run-transaction-endpoint.ts b/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/run-transaction-endpoint.ts index 400002148c..c90eee32be 100644 --- a/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/run-transaction-endpoint.ts +++ b/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/run-transaction-endpoint.ts @@ -12,7 +12,10 @@ import { IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginLedgerConnectorBesu } from "../plugin-ledger-connector-besu"; @@ -93,7 +96,7 @@ export class RunTransactionEndpoint implements IWebServiceEndpoint { this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `Internal server Error`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/sign-transaction-endpoint-v1.ts b/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/sign-transaction-endpoint-v1.ts index 3cdef13a33..3c7c7c8867 100644 --- a/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/sign-transaction-endpoint-v1.ts +++ b/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/sign-transaction-endpoint-v1.ts @@ -1,6 +1,9 @@ import { Express, Request, Response } from "express"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { IWebServiceEndpoint, @@ -101,16 +104,28 @@ export class BesuSignTransactionEndpointV1 implements IWebServiceEndpoint { } } catch (ex) { this.log.error(`${fnTag} failed to serve request`, ex); - if (typeof ex === 'object' && ex !== null) { - if ('message' in ex && typeof ex.message === 'string') { - const errorMsg = ex.message - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) - } - } - else { + if ( + typeof ex === "object" && + ex !== null && + "message" in ex && + typeof ex.message === "string" + ) { + const errorMsg = ex.message; + handleRestEndpointException({ + errorMsg, + log: this.log, + error: ex, + res, + }); + } else { this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `Internal server Error`; - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) + handleRestEndpointException({ + errorMsg, + log: this.log, + error: ex, + res, + }); } } } diff --git a/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/invoke-contract.test.ts b/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/invoke-contract.test.ts index 45873edac3..771a58283c 100644 --- a/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/invoke-contract.test.ts +++ b/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/invoke-contract.test.ts @@ -200,8 +200,10 @@ describe(testCase, () => { }); expect(setNameOutInvalid.transactionReceipt).toBeFalsy(); } catch (error) { - if (typeof error === 'object' && error !== null) { - if ('message' in error && typeof error.message === 'string') { expect(error.message).toMatch("Nonce too low"); } + if (typeof error === "object" && error !== null) { + if ("message" in error && typeof error.message === "string") { + expect(error.message).toMatch("Nonce too low"); + } } } @@ -301,8 +303,10 @@ describe(testCase, () => { }); expect(setNameOutInvalid.transactionReceipt).toBeFalsy(); } catch (error) { - if (typeof error === 'object' && error !== null) { - if ('message' in error && typeof error.message === 'string') { expect(error.message).toMatch("Nonce too low"); } + if (typeof error === "object" && error !== null) { + if ("message" in error && typeof error.message === "string") { + expect(error.message).toMatch("Nonce too low"); + } } } diff --git a/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/openapi/openapi-validation.test.ts b/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/openapi/openapi-validation.test.ts index e96f2689aa..9e08a582c4 100644 --- a/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/openapi/openapi-validation.test.ts +++ b/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/openapi/openapi-validation.test.ts @@ -214,7 +214,7 @@ describe("PluginLedgerConnectorBesu", () => { parameters as unknown as DeployContractSolidityBytecodeV1Request, ); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; expect(e?.response?.status).toEqual(400); const fields = e?.response?.data.map((param: { readonly path: string }) => param.path.replace("/body/", ""), @@ -246,7 +246,7 @@ describe("PluginLedgerConnectorBesu", () => { parameters as DeployContractSolidityBytecodeV1Request, ); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; expect(e?.response?.status).toEqual(400); const fields = e?.response?.data.map((param: { readonly path: string }) => param.path.replace("/body/", ""), @@ -293,7 +293,7 @@ describe("PluginLedgerConnectorBesu", () => { parameters as any as InvokeContractV1Request, ); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; expect(e?.response?.status).toEqual(400); const fields = e?.response?.data.map((param: { readonly path: string }) => param.path.replace("/body/", ""), @@ -320,7 +320,7 @@ describe("PluginLedgerConnectorBesu", () => { }; await apiClient.invokeContractV1(parameters as InvokeContractV1Request); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; expect(e?.response?.status).toEqual(400); const fields = e?.response?.data.map((param: { readonly path: string }) => param.path.replace("/body/", ""), @@ -374,7 +374,7 @@ describe("PluginLedgerConnectorBesu", () => { }; await apiClient.runTransactionV1(parameters as RunTransactionRequest); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; expect(e?.response?.status).toEqual(400); const fields = e?.response?.data.map((param: { readonly path: string }) => param.path.replace("/body/", ""), @@ -406,7 +406,7 @@ describe("PluginLedgerConnectorBesu", () => { }; await apiClient.runTransactionV1(parameters as RunTransactionRequest); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; expect(e?.response?.status).toEqual(400); const fields = e?.response?.data.map((param: { readonly path: string }) => param.path.replace("/body/", ""), @@ -498,7 +498,7 @@ describe("PluginLedgerConnectorBesu", () => { await apiClient.signTransactionV1(parameters as SignTransactionRequest); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; expect(e?.response?.status).toEqual(400); const fields = e?.response?.data.map((param: any) => param.path.replace("/body/", ""), @@ -542,7 +542,7 @@ describe("PluginLedgerConnectorBesu", () => { await apiClient.signTransactionV1(parameters as SignTransactionRequest); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; expect(e?.response?.status).toEqual(400); const fields = e?.response?.data.map((param: { readonly path: string }) => param.path.replace("/body/", ""), @@ -563,7 +563,7 @@ describe("PluginLedgerConnectorBesu", () => { const parameters = {}; await apiClient.getBalanceV1(parameters as GetBalanceV1Request); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; expect(e?.response?.status).toEqual(400); const fields = e?.response?.data.map((param: { readonly path: string }) => param.path.replace("/body/", ""), @@ -580,7 +580,7 @@ describe("PluginLedgerConnectorBesu", () => { }; await apiClient.getBalanceV1(parameters as GetBalanceV1Request); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; expect(e?.response?.status).toEqual(400); const fields = e?.response?.data.map((param: { readonly path: string }) => param.path.replace("/body/", ""), @@ -601,7 +601,7 @@ describe("PluginLedgerConnectorBesu", () => { const parameters = {}; await apiClient.getBlockV1(parameters as GetBlockV1Request); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; expect(e?.response?.status).toEqual(400); const fields = e?.response?.data.map((param: { readonly path: string }) => param.path.replace("/body/", ""), @@ -618,7 +618,7 @@ describe("PluginLedgerConnectorBesu", () => { }; await apiClient.getBlockV1(parameters as GetBlockV1Request); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; expect(e?.response?.status).toEqual(400); const fields = e?.response?.data.map((param: { readonly path: string }) => param.path.replace("/body/", ""), @@ -641,7 +641,7 @@ describe("PluginLedgerConnectorBesu", () => { const parameters = {}; await apiClient.getPastLogsV1(parameters as GetPastLogsV1Request); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; expect(e?.response?.status).toEqual(400); const fields = e?.response?.data.map((param: { readonly path: string }) => param.path.replace("/body/", ""), @@ -658,7 +658,7 @@ describe("PluginLedgerConnectorBesu", () => { }; await apiClient.getPastLogsV1(parameters as GetPastLogsV1Request); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; expect(e?.response?.status).toEqual(400); const fields = e?.response?.data.map((param: { readonly path: string }) => param.path.replace("/body/", ""), @@ -709,7 +709,7 @@ describe("PluginLedgerConnectorBesu", () => { const parameters = {}; await apiClient.getBesuRecordV1(parameters as GetBesuRecordV1Request); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; expect(e?.response?.status).toEqual(400); const fields = e?.response?.data.map((param: any) => param.path.replace("/body/", ""), @@ -726,7 +726,7 @@ describe("PluginLedgerConnectorBesu", () => { }; await apiClient.getBesuRecordV1(parameters as GetBesuRecordV1Request); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; expect(e?.response?.status).toEqual(400); const fields = e?.response?.data.map((param: { readonly path: string }) => param.path.replace("/body/", ""), diff --git a/packages/cactus-plugin-ledger-connector-cdl/src/main/typescript/web-services/get-lineage-v1-endpoint.ts b/packages/cactus-plugin-ledger-connector-cdl/src/main/typescript/web-services/get-lineage-v1-endpoint.ts index d511a572fb..2a4ee2a392 100644 --- a/packages/cactus-plugin-ledger-connector-cdl/src/main/typescript/web-services/get-lineage-v1-endpoint.ts +++ b/packages/cactus-plugin-ledger-connector-cdl/src/main/typescript/web-services/get-lineage-v1-endpoint.ts @@ -12,10 +12,12 @@ import { LogLevelDesc, LoggerProvider, IAsyncProvider, - safeStringifyException, } from "@hyperledger/cactus-common"; -import { registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginLedgerConnectorCDL } from "../plugin-ledger-connector-cdl"; import OAS from "../../json/openapi.json"; @@ -89,11 +91,8 @@ export class GetLineageDataEndpoint implements IWebServiceEndpoint { res.status(200).json(await this.options.connector.getLineage(req.body)); } catch (ex) { this.log.error(`Crash while serving ${reqTag}`, ex); - - res.status(500).json({ - message: "Internal Server Error", - error: safeStringifyException(ex), - }); + const errorMsg = "Internal Server Error"; + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-ledger-connector-cdl/src/main/typescript/web-services/register-history-data-v1-endpoint.ts b/packages/cactus-plugin-ledger-connector-cdl/src/main/typescript/web-services/register-history-data-v1-endpoint.ts index 81155dc4e2..0dc88a3b9c 100644 --- a/packages/cactus-plugin-ledger-connector-cdl/src/main/typescript/web-services/register-history-data-v1-endpoint.ts +++ b/packages/cactus-plugin-ledger-connector-cdl/src/main/typescript/web-services/register-history-data-v1-endpoint.ts @@ -12,10 +12,12 @@ import { LogLevelDesc, LoggerProvider, IAsyncProvider, - safeStringifyException, } from "@hyperledger/cactus-common"; -import { registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginLedgerConnectorCDL } from "../plugin-ledger-connector-cdl"; import OAS from "../../json/openapi.json"; @@ -92,10 +94,8 @@ export class RegisterHistoryDataEndpoint implements IWebServiceEndpoint { } catch (ex) { this.log.error(`Crash while serving ${reqTag}`, ex); - res.status(500).json({ - message: "Internal Server Error", - error: safeStringifyException(ex), - }); + const errorMsg = "Internal Server Error"; + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-ledger-connector-cdl/src/main/typescript/web-services/search-lineage-by-globaldata-v1-endpoint.ts b/packages/cactus-plugin-ledger-connector-cdl/src/main/typescript/web-services/search-lineage-by-globaldata-v1-endpoint.ts index 1e6d7e7e8c..f360b3cce0 100644 --- a/packages/cactus-plugin-ledger-connector-cdl/src/main/typescript/web-services/search-lineage-by-globaldata-v1-endpoint.ts +++ b/packages/cactus-plugin-ledger-connector-cdl/src/main/typescript/web-services/search-lineage-by-globaldata-v1-endpoint.ts @@ -12,10 +12,12 @@ import { LogLevelDesc, LoggerProvider, IAsyncProvider, - safeStringifyException, } from "@hyperledger/cactus-common"; -import { registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginLedgerConnectorCDL } from "../plugin-ledger-connector-cdl"; import OAS from "../../json/openapi.json"; @@ -92,10 +94,8 @@ export class SearchLineageByGlobalDataEndpoint implements IWebServiceEndpoint { } catch (ex) { this.log.error(`Crash while serving ${reqTag}`, ex); - res.status(500).json({ - message: "Internal Server Error", - error: safeStringifyException(ex), - }); + const errorMsg = "Internal Server Error"; + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-ledger-connector-cdl/src/main/typescript/web-services/search-lineage-by-header-v1-endpoint.ts b/packages/cactus-plugin-ledger-connector-cdl/src/main/typescript/web-services/search-lineage-by-header-v1-endpoint.ts index 31f8de6948..13c7667c4a 100644 --- a/packages/cactus-plugin-ledger-connector-cdl/src/main/typescript/web-services/search-lineage-by-header-v1-endpoint.ts +++ b/packages/cactus-plugin-ledger-connector-cdl/src/main/typescript/web-services/search-lineage-by-header-v1-endpoint.ts @@ -12,10 +12,12 @@ import { LogLevelDesc, LoggerProvider, IAsyncProvider, - safeStringifyException, } from "@hyperledger/cactus-common"; -import { registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginLedgerConnectorCDL } from "../plugin-ledger-connector-cdl"; import OAS from "../../json/openapi.json"; @@ -91,11 +93,8 @@ export class SearchLineageByHeaderEndpoint implements IWebServiceEndpoint { .json(await this.options.connector.searchLineageByHeader(req.body)); } catch (ex) { this.log.error(`Crash while serving ${reqTag}`, ex); - - res.status(500).json({ - message: "Internal Server Error", - error: safeStringifyException(ex), - }); + const errorMsg = "Internal Server Error"; + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-ledger-connector-corda/src/main/typescript/web-services/deploy-contract-jars-endpoint.ts b/packages/cactus-plugin-ledger-connector-corda/src/main/typescript/web-services/deploy-contract-jars-endpoint.ts index c11b1f4e35..7c6845e7d0 100644 --- a/packages/cactus-plugin-ledger-connector-corda/src/main/typescript/web-services/deploy-contract-jars-endpoint.ts +++ b/packages/cactus-plugin-ledger-connector-corda/src/main/typescript/web-services/deploy-contract-jars-endpoint.ts @@ -134,12 +134,19 @@ export class DeployContractJarsEndpoint implements IWebServiceEndpoint { res.json(body); } catch (ex) { this.log.error(`${fnTag} failed to serve request`, ex); - if (typeof ex === 'object' && ex !== null) { - if ('message' in ex && typeof ex.message === 'string') { - const errorMsg = ex.message - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) - - } + if ( + typeof ex === "object" && + ex !== null && + "message" in ex && + typeof ex.message === "string" + ) { + const errorMsg = ex.message; + handleRestEndpointException({ + errorMsg, + log: this.log, + error: ex, + res, + }); } } } diff --git a/packages/cactus-plugin-ledger-connector-corda/src/main/typescript/web-services/diagnose-node-endpoint-v1.ts b/packages/cactus-plugin-ledger-connector-corda/src/main/typescript/web-services/diagnose-node-endpoint-v1.ts index 1cc121571f..757d2de944 100644 --- a/packages/cactus-plugin-ledger-connector-corda/src/main/typescript/web-services/diagnose-node-endpoint-v1.ts +++ b/packages/cactus-plugin-ledger-connector-corda/src/main/typescript/web-services/diagnose-node-endpoint-v1.ts @@ -17,7 +17,10 @@ import { import OAS from "../../json/openapi.json"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { DefaultApi, DiagnoseNodeV1Request, @@ -97,12 +100,19 @@ export class DiagnoseNodeEndpointV1 implements IWebServiceEndpoint { res.send(resBody); } catch (ex) { this.log.error(`${fnTag} failed to serve request`, ex); - if (typeof ex === 'object' && ex !== null) { - if ('message' in ex && typeof ex.message === 'string') { - const errorMsg = ex.message - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) - - } + if ( + typeof ex === "object" && + ex !== null && + "message" in ex && + typeof ex.message === "string" + ) { + const errorMsg = ex.message; + handleRestEndpointException({ + errorMsg, + log: this.log, + error: ex, + res, + }); } } } diff --git a/packages/cactus-plugin-ledger-connector-corda/src/main/typescript/web-services/get-prometheus-exporter-metrics-endpoint-v1.ts b/packages/cactus-plugin-ledger-connector-corda/src/main/typescript/web-services/get-prometheus-exporter-metrics-endpoint-v1.ts index 9ad7d8b342..fe6c2837df 100644 --- a/packages/cactus-plugin-ledger-connector-corda/src/main/typescript/web-services/get-prometheus-exporter-metrics-endpoint-v1.ts +++ b/packages/cactus-plugin-ledger-connector-corda/src/main/typescript/web-services/get-prometheus-exporter-metrics-endpoint-v1.ts @@ -16,7 +16,10 @@ import { import OAS from "../../json/openapi.json"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginLedgerConnectorCorda } from "../plugin-ledger-connector-corda"; @@ -26,7 +29,8 @@ export interface IGetPrometheusExporterMetricsEndpointV1Options { } export class GetPrometheusExporterMetricsEndpointV1 - implements IWebServiceEndpoint { + implements IWebServiceEndpoint +{ private readonly log: Logger; constructor( @@ -93,12 +97,19 @@ export class GetPrometheusExporterMetricsEndpointV1 res.send(resBody); } catch (ex) { this.log.error(`${fnTag} failed to serve request`, ex); - if (typeof ex === 'object' && ex !== null) { - if ('message' in ex && typeof ex.message === 'string') { - const errorMsg = ex.message - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) - - } + if ( + typeof ex === "object" && + ex !== null && + "message" in ex && + typeof ex.message === "string" + ) { + const errorMsg = ex.message; + handleRestEndpointException({ + errorMsg, + log: this.log, + error: ex, + res, + }); } } } diff --git a/packages/cactus-plugin-ledger-connector-corda/src/main/typescript/web-services/invoke-contract-endpoint-v1.ts b/packages/cactus-plugin-ledger-connector-corda/src/main/typescript/web-services/invoke-contract-endpoint-v1.ts index 4789f322a4..963d1b6d98 100644 --- a/packages/cactus-plugin-ledger-connector-corda/src/main/typescript/web-services/invoke-contract-endpoint-v1.ts +++ b/packages/cactus-plugin-ledger-connector-corda/src/main/typescript/web-services/invoke-contract-endpoint-v1.ts @@ -17,7 +17,10 @@ import { import OAS from "../../json/openapi.json"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { DefaultApi, InvokeContractV1Request, @@ -97,12 +100,19 @@ export class InvokeContractEndpointV1 implements IWebServiceEndpoint { res.send(resBody); } catch (ex) { this.log.error(`${fnTag} failed to serve request`, ex); - if (typeof ex === 'object' && ex !== null) { - if ('message' in ex && typeof ex.message === 'string') { - const errorMsg = ex.message - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) - - } + if ( + typeof ex === "object" && + ex !== null && + "message" in ex && + typeof ex.message === "string" + ) { + const errorMsg = ex.message; + handleRestEndpointException({ + errorMsg, + log: this.log, + error: ex, + res, + }); } } } diff --git a/packages/cactus-plugin-ledger-connector-corda/src/main/typescript/web-services/list-flows-endpoint-v1.ts b/packages/cactus-plugin-ledger-connector-corda/src/main/typescript/web-services/list-flows-endpoint-v1.ts index b1429c7b6d..68abe024ac 100644 --- a/packages/cactus-plugin-ledger-connector-corda/src/main/typescript/web-services/list-flows-endpoint-v1.ts +++ b/packages/cactus-plugin-ledger-connector-corda/src/main/typescript/web-services/list-flows-endpoint-v1.ts @@ -17,7 +17,10 @@ import { import OAS from "../../json/openapi.json"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { DefaultApi, ListFlowsV1Request, @@ -102,12 +105,19 @@ export class ListFlowsEndpointV1 implements IWebServiceEndpoint { res.send(resBody); } catch (ex) { this.log.error(`${fnTag} failed to serve request`, ex); - if (typeof ex === 'object' && ex !== null) { - if ('message' in ex && typeof ex.message === 'string') { - const errorMsg = ex.message - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) - - } + if ( + typeof ex === "object" && + ex !== null && + "message" in ex && + typeof ex.message === "string" + ) { + const errorMsg = ex.message; + handleRestEndpointException({ + errorMsg, + log: this.log, + error: ex, + res, + }); } } } diff --git a/packages/cactus-plugin-ledger-connector-corda/src/main/typescript/web-services/network-map-endpoint-v1.ts b/packages/cactus-plugin-ledger-connector-corda/src/main/typescript/web-services/network-map-endpoint-v1.ts index e5b8ff37b9..8dd887804e 100644 --- a/packages/cactus-plugin-ledger-connector-corda/src/main/typescript/web-services/network-map-endpoint-v1.ts +++ b/packages/cactus-plugin-ledger-connector-corda/src/main/typescript/web-services/network-map-endpoint-v1.ts @@ -17,7 +17,10 @@ import { import OAS from "../../json/openapi.json"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { DefaultApi, NodeInfo } from "../generated/openapi/typescript-axios"; export interface INetworkMapEndpointV1Options { @@ -93,12 +96,19 @@ export class NetworkMapEndpointV1 implements IWebServiceEndpoint { res.send(resBody); } catch (ex) { this.log.error(`${fnTag} failed to serve request`, ex); - if (typeof ex === 'object' && ex !== null) { - if ('message' in ex && typeof ex.message === 'string') { - const errorMsg = ex.message - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) - - } + if ( + typeof ex === "object" && + ex !== null && + "message" in ex && + typeof ex.message === "string" + ) { + const errorMsg = ex.message; + handleRestEndpointException({ + errorMsg, + log: this.log, + error: ex, + res, + }); } } } diff --git a/packages/cactus-plugin-ledger-connector-corda/src/test/typescript/integration/openapi/openapi-validation.test.ts b/packages/cactus-plugin-ledger-connector-corda/src/test/typescript/integration/openapi/openapi-validation.test.ts index 0d731bcf83..3649aa422b 100644 --- a/packages/cactus-plugin-ledger-connector-corda/src/test/typescript/integration/openapi/openapi-validation.test.ts +++ b/packages/cactus-plugin-ledger-connector-corda/src/test/typescript/integration/openapi/openapi-validation.test.ts @@ -435,7 +435,7 @@ test(testCase, async (t: Test) => { await apiClient.deployContractJarsV1(depReq); t2.fail(`${fDeploy} - ${cWithoutParams}: should fail`); } catch (e) { - const err = e as AxiosError<{ status: number }> + const err = e as AxiosError<{ status: number }>; t2.equal( err.response?.data?.status, @@ -456,7 +456,7 @@ test(testCase, async (t: Test) => { await apiClient.invokeContractV1(req); t2.fail(`${fInvoke} - ${cWithoutParams}: should fail`); } catch (e) { - const err = e as AxiosError<{ status: number }> + const err = e as AxiosError<{ status: number }>; t2.equal( err.response?.data?.status, @@ -477,7 +477,7 @@ test(testCase, async (t: Test) => { await apiClient.deployContractJarsV1(depReq); t2.fail(`${fDeploy} - ${cInvalidParams}: should fail`); } catch (e) { - const err = e as AxiosError<{ status: number }> + const err = e as AxiosError<{ status: number }>; t2.equal( err.response?.data?.status, @@ -494,7 +494,7 @@ test(testCase, async (t: Test) => { await apiClient.listFlowsV1(req); t2.fail(`${fFlows} - ${cInvalidParams}: should fail`); } catch (e) { - const err = e as AxiosError<{ status: number }> + const err = e as AxiosError<{ status: number }>; t2.equal( err.response?.data?.status, @@ -511,7 +511,7 @@ test(testCase, async (t: Test) => { await apiClient.diagnoseNodeV1(req); t2.fail(`${fDiagnose} - ${cInvalidParams}: should fail`); } catch (e) { - const err = e as AxiosError<{ status: number }> + const err = e as AxiosError<{ status: number }>; t2.equal( err.response?.data?.status, @@ -767,7 +767,7 @@ test(testCase, async (t: Test) => { await apiClient.invokeContractV1(req); t2.fail(`${fInvoke} - ${cInvalidParams}: should fail`); } catch (e) { - const err = e as AxiosError<{ status: number }> + const err = e as AxiosError<{ status: number }>; t2.equal( err.response?.data?.status, @@ -780,6 +780,3 @@ test(testCase, async (t: Test) => { t.end(); }); - - - diff --git a/packages/cactus-plugin-ledger-connector-ethereum/src/main/typescript/plugin-ledger-connector-ethereum.ts b/packages/cactus-plugin-ledger-connector-ethereum/src/main/typescript/plugin-ledger-connector-ethereum.ts index 62163b72a9..1e434bf8ed 100644 --- a/packages/cactus-plugin-ledger-connector-ethereum/src/main/typescript/plugin-ledger-connector-ethereum.ts +++ b/packages/cactus-plugin-ledger-connector-ethereum/src/main/typescript/plugin-ledger-connector-ethereum.ts @@ -94,9 +94,9 @@ const waitForWsProviderRequestsTimeout = 5 * 1000; // 5s const waitForWsProviderRequestsStep = 500; // 500ms type RunContractDeploymentInput = { web3SigningCredential: - | Web3SigningCredentialCactiKeychainRef - | Web3SigningCredentialGethKeychainPassword - | Web3SigningCredentialPrivateKeyHex; + | Web3SigningCredentialCactiKeychainRef + | Web3SigningCredentialGethKeychainPassword + | Web3SigningCredentialPrivateKeyHex; contractJSON: ContractJSON; gasConfig?: GasTransactionConfig; constructorArgs?: unknown[]; @@ -131,14 +131,15 @@ export interface IPluginLedgerConnectorEthereumOptions export class PluginLedgerConnectorEthereum implements - IPluginLedgerConnector< - DeployContractV1Request, - RunTransactionResponse, - RunTransactionRequest, - RunTransactionResponse - >, - ICactusPlugin, - IPluginWebService { + IPluginLedgerConnector< + DeployContractV1Request, + RunTransactionResponse, + RunTransactionRequest, + RunTransactionResponse + >, + ICactusPlugin, + IPluginWebService +{ private readonly pluginRegistry: PluginRegistry; public prometheusExporter: PrometheusExporter; private readonly instanceId: string; @@ -695,16 +696,16 @@ export class PluginLedgerConnectorEthereum } else { throw new Error( `${fnTag} Expected pre-signed raw transaction ` + - ` since signing credential is specified as` + - `Web3SigningCredentialType.NONE`, + ` since signing credential is specified as` + + `Web3SigningCredentialType.NONE`, ); } } default: { throw new Error( `${fnTag} Unrecognized Web3SigningCredentialType: ` + - `${req.web3SigningCredential.type} Supported ones are: ` + - `${Object.values(Web3SigningCredentialType).join(";")}`, + `${req.web3SigningCredential.type} Supported ones are: ` + + `${Object.values(Web3SigningCredentialType).join(";")}`, ); } } @@ -801,15 +802,14 @@ export class PluginLedgerConnectorEthereum if (ex instanceof Error) { throw new Error( `${fnTag} Failed to invoke web3.eth.personal.sendTransaction(). ` + - `InnerException: ${ex.stack}`, + `InnerException: ${ex.stack}`, ); } else { throw new Error( `${fnTag} Failed to invoke web3.eth.personal.sendTransaction(). ` + - `Error: ${ex}`, + `Error: ${ex}`, ); } - } } @@ -837,7 +837,7 @@ export class PluginLedgerConnectorEthereum } else { throw new Error( `${fnTag} Failed to sign eth transaction. ` + - `signedTransaction.rawTransaction is blank after .signTransaction().`, + `signedTransaction.rawTransaction is blank after .signTransaction().`, ); } } diff --git a/packages/cactus-plugin-ledger-connector-ethereum/src/main/typescript/web-services/get-prometheus-exporter-metrics-v1-endpoint.ts b/packages/cactus-plugin-ledger-connector-ethereum/src/main/typescript/web-services/get-prometheus-exporter-metrics-v1-endpoint.ts index 792e2b25bd..bad03c05d6 100644 --- a/packages/cactus-plugin-ledger-connector-ethereum/src/main/typescript/web-services/get-prometheus-exporter-metrics-v1-endpoint.ts +++ b/packages/cactus-plugin-ledger-connector-ethereum/src/main/typescript/web-services/get-prometheus-exporter-metrics-v1-endpoint.ts @@ -1,6 +1,9 @@ import { Express, Request, Response } from "express"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import OAS from "../../json/openapi.json"; @@ -16,7 +19,6 @@ import { LoggerProvider, Checks, IAsyncProvider, - safeStringifyException, } from "@hyperledger/cactus-common"; import { PluginLedgerConnectorEthereum } from "../plugin-ledger-connector-ethereum"; @@ -27,7 +29,8 @@ export interface IGetPrometheusExporterMetricsEndpointV1Options { } export class GetPrometheusExporterMetricsEndpointV1 - implements IWebServiceEndpoint { + implements IWebServiceEndpoint +{ private readonly log: Logger; constructor( @@ -84,6 +87,7 @@ export class GetPrometheusExporterMetricsEndpointV1 async handleRequest(req: Request, res: Response): Promise { const fnTag = "GetPrometheusExporterMetrics#handleRequest()"; + const reqTag = `${this.getVerbLowerCase()} - ${this.getPath()}`; const verbUpper = this.getVerbLowerCase().toUpperCase(); this.log.debug(`${verbUpper} ${this.getPath()}`); @@ -92,16 +96,21 @@ export class GetPrometheusExporterMetricsEndpointV1 .status(200) .send(await this.options.connector.getPrometheusExporterMetrics()); } catch (ex) { - if (typeof ex === 'object' && ex !== null) { - - if ('message' in ex && typeof ex.message === 'string') { - - const errorMsg = ex.message - - handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) - - } - + if ( + typeof ex === "object" && + ex !== null && + "message" in ex && + typeof ex.message === "string" + ) { + this.log.error(`Crash while serving ${reqTag} in ${fnTag}`, ex); + const errorMsg = ex.message; + + handleRestEndpointException({ + errorMsg, + log: this.log, + error: ex, + res, + }); } } } diff --git a/packages/cactus-plugin-ledger-connector-ethereum/src/test/typescript/integration/geth-contract-deploy-and-invoke-using-json-object-v1.test.ts b/packages/cactus-plugin-ledger-connector-ethereum/src/test/typescript/integration/geth-contract-deploy-and-invoke-using-json-object-v1.test.ts index 134eb63cd5..8c6815ad9a 100644 --- a/packages/cactus-plugin-ledger-connector-ethereum/src/test/typescript/integration/geth-contract-deploy-and-invoke-using-json-object-v1.test.ts +++ b/packages/cactus-plugin-ledger-connector-ethereum/src/test/typescript/integration/geth-contract-deploy-and-invoke-using-json-object-v1.test.ts @@ -52,9 +52,9 @@ const containerImageVersion = "2023-07-27-2a8c48ed6"; describe("Ethereum contract deploy and invoke using keychain tests", () => { const keychainEntryKey = uuidV4(); let testEthAccount: { - address: HexString; - privateKey: HexString; - }, + address: HexString; + privateKey: HexString; + }, web3: InstanceType, addressInfo, address: string, 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 ed262694d7..4a0fc3869e 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 @@ -7,7 +7,6 @@ import { LogLevelDesc, LoggerProvider, IAsyncProvider, - safeStringifyException, } from "@hyperledger/cactus-common"; import { @@ -16,7 +15,10 @@ import { IEndpointAuthzOptions, } from "@hyperledger/cactus-core-api"; -import { handleRestEndpointException, 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"; @@ -98,21 +100,13 @@ export class DeployContractEndpointV1 implements IWebServiceEndpoint { res.json(resBody); } catch (ex) { this.log.error(`${fnTag} failed to serve contract deploy request`, ex); - res.status(HttpStatus.INTERNAL_SERVER_ERROR).json({ - message: "Internal Server Error", - error: safeStringifyException(ex), + const errorMsg = `Internal server Error`; + handleRestEndpointException({ + errorMsg, + log: this.log, + error: ex, + res, }); } } } - - -// { -// this.log.error(`${fnTag} failed to serve contract deploy request`, ex); -// if (typeof ex === 'object' && ex !== null) { -// if ('message' in ex && typeof ex.message === 'string') {= -// const errorMsg = ex.message -// handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }) -// } -// } -// } \ No newline at end of file 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 763ed05573..de9a9cdb4e 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 @@ -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"; @@ -87,12 +89,10 @@ export class GetBlockEndpointV1 implements IWebServiceEndpoint { try { res.status(200).send(await this.opts.connector.getBlock(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) { + this.log.error(`Crash while serving ${fnTag}`, ex); + const errorMsg = "Internal Server Error"; + 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 b5b6794407..2fd6b45bd0 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 @@ -6,7 +6,6 @@ import { LogLevelDesc, Checks, IAsyncProvider, - safeStringifyException, } from "@hyperledger/cactus-common"; import { @@ -17,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"; @@ -27,7 +29,8 @@ export interface IGetPrometheusExporterMetricsEndpointV1Options { } export class GetPrometheusExporterMetricsEndpointV1 - implements IWebServiceEndpoint { + implements IWebServiceEndpoint +{ private readonly log: Logger; constructor( @@ -93,10 +96,8 @@ export class GetPrometheusExporterMetricsEndpointV1 res.send(resBody); } catch (ex) { this.log.error(`${fnTag} failed to serve request`, ex); - res.status(500).json({ - message: "Internal Server Error", - error: safeStringifyException(ex), - }); + const errorMsg = "Internal Server Error"; + 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 943188d0ac..57d002121b 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 @@ -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 { RunTransactionRequest } from "../generated/openapi/typescript-axios"; @@ -27,7 +29,8 @@ export interface IRunTransactionEndpointV1Options { } export class GetTransactionReceiptByTxIDEndpointV1 - implements IWebServiceEndpoint { + implements IWebServiceEndpoint +{ private readonly log: Logger; constructor(public readonly opts: IRunTransactionEndpointV1Options) { @@ -95,10 +98,8 @@ export class GetTransactionReceiptByTxIDEndpointV1 res.json(resBody); } catch (ex) { this.log.error(`${fnTag} failed to serve request`, ex); - res.status(500).json({ - message: "Internal Server Error", - error: safeStringifyException(ex), - }); + const errorMsg = "Internal Server Error"; + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/plugin-ledger-connector-fabric.ts b/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/plugin-ledger-connector-fabric.ts index c345bff356..1bb403ab0f 100644 --- a/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/plugin-ledger-connector-fabric.ts +++ b/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/plugin-ledger-connector-fabric.ts @@ -188,14 +188,15 @@ export interface IPluginLedgerConnectorFabricOptions export class PluginLedgerConnectorFabric implements - IPluginLedgerConnector< - DeployContractV1Request, - DeployContractV1Response, - RunTransactionRequest, - RunTransactionResponse - >, - ICactusPlugin, - IPluginWebService { + IPluginLedgerConnector< + DeployContractV1Request, + DeployContractV1Response, + RunTransactionRequest, + RunTransactionResponse + >, + ICactusPlugin, + IPluginWebService +{ public static readonly CLASS_NAME = "PluginLedgerConnectorFabric"; private readonly instanceId: string; private readonly log: Logger; @@ -1114,11 +1115,16 @@ export class PluginLedgerConnectorFabric } } catch (ex) { this.log.error(`Building transient map crashed: `, ex); - if (typeof ex === 'object' && ex !== null) { - if ('message' in ex && typeof ex.message === 'string') { - throw new Error(`Unable to build the transient map: ${ex.message}`); - } - } else { throw new Error(`Unable to build the transient map. Error: ${ex}`); } + if ( + typeof ex === "object" && + ex !== null && + "message" in ex && + typeof ex.message === "string" + ) { + throw new Error(`Unable to build the transient map: ${ex.message}`); + } else { + throw new Error(`Unable to build the transient map. Error: ${ex}`); + } } return transientMap; @@ -1223,9 +1229,10 @@ export class PluginLedgerConnectorFabric if (ex instanceof Error) { throw new Error(`${fnTag} Inner Exception: ${ex?.message}`); - } else { throw new Error(`${fnTag} Exception: ${ex}`) } + } else { + throw new Error(`${fnTag} Exception: ${ex}`); + } } - } public async getTransactionReceiptByTxID( @@ -1264,8 +1271,9 @@ export class PluginLedgerConnectorFabric if (ex instanceof Error) { throw new Error(`${fnTag} Inner Exception: ${ex?.message}`); - } else { throw new Error(`${fnTag} Exception: ${ex}`) } - + } else { + throw new Error(`${fnTag} Exception: ${ex}`); + } } } @@ -1303,7 +1311,9 @@ export class PluginLedgerConnectorFabric this.log.error(`enrollAdmin() Failure:`, ex); if (ex instanceof Error) { throw new Error(`${fnTag} Inner Exception: ${ex?.message}`); - } else { throw new Error(`${fnTag} Exception: ${ex}`) } + } else { + throw new Error(`${fnTag} Exception: ${ex}`); + } } } /** @@ -1647,8 +1657,10 @@ export class PluginLedgerConnectorFabric } this.log.info( - `Created channel for ${channelName} with ${channel.getMspids().length - } Mspids, ${channel.getCommitters().length} commiters, ${channel.getEndorsers().length + `Created channel for ${channelName} with ${ + channel.getMspids().length + } Mspids, ${channel.getCommitters().length} commiters, ${ + channel.getEndorsers().length } endorsers`, ); @@ -1777,10 +1789,11 @@ export class PluginLedgerConnectorFabric let endorsedMethodResponse: Buffer | undefined; for (const response of endorsementResponse.responses) { - const endorsementStatus = `${response.connection.name}: ${response.response.status - } message ${response.response.message}, endorsement: ${Boolean( - response.endorsement, - )}`; + const endorsementStatus = `${response.connection.name}: ${ + response.response.status + } message ${response.response.message}, endorsement: ${Boolean( + response.endorsement, + )}`; if (response.response.status !== 200 || !response.endorsement) { this.log.warn(`Endorsement from peer ERROR: ${endorsementStatus}`); 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..d2cd9c883c 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"; @@ -91,12 +93,10 @@ export class RunDelegatedSignTransactionEndpointV1 res .status(200) .json(await this.opts.connector.transactDelegatedSign(req.body)); - } catch (error) { + } catch (ex) { this.log.error(`Crash while serving ${fnTag}`, error); - res.status(500).json({ - message: "Internal Server Error", - error: safeStringifyException(error), - }); + const errorMsg = "Internal Server Error"; + 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..c611b82887 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"; @@ -85,12 +87,10 @@ export class RunTransactionEndpointV1 implements IWebServiceEndpoint { try { res.status(200).json(await this.opts.connector.transact(req.body)); - } catch (error) { + } catch (ex) { this.log.error(`Crash while serving ${fnTag}`, error); - res.status(500).json({ - message: "Internal Server Error", - error: safeStringifyException(error), - }); + const errorMsg = "Internal Server Error"; + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-ledger-connector-fabric/src/test/typescript/integration/openapi/openapi-validation-go.test.ts b/packages/cactus-plugin-ledger-connector-fabric/src/test/typescript/integration/openapi/openapi-validation-go.test.ts index 5fc7716b01..6ed4ddb048 100644 --- a/packages/cactus-plugin-ledger-connector-fabric/src/test/typescript/integration/openapi/openapi-validation-go.test.ts +++ b/packages/cactus-plugin-ledger-connector-fabric/src/test/typescript/integration/openapi/openapi-validation-go.test.ts @@ -230,7 +230,7 @@ test(testCase, async (t: Test) => { parameters as any as DeployContractGoSourceV1Request, ); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, @@ -293,7 +293,7 @@ test(testCase, async (t: Test) => { parameters as any as DeployContractGoSourceV1Request, ); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, diff --git a/packages/cactus-plugin-ledger-connector-fabric/src/test/typescript/integration/openapi/openapi-validation.test.ts b/packages/cactus-plugin-ledger-connector-fabric/src/test/typescript/integration/openapi/openapi-validation.test.ts index e638c4fadd..ec36ae2469 100644 --- a/packages/cactus-plugin-ledger-connector-fabric/src/test/typescript/integration/openapi/openapi-validation.test.ts +++ b/packages/cactus-plugin-ledger-connector-fabric/src/test/typescript/integration/openapi/openapi-validation.test.ts @@ -292,7 +292,7 @@ test(testCase, async (t: Test) => { parameters as unknown as DeployContractV1Request, ); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, @@ -334,7 +334,7 @@ test(testCase, async (t: Test) => { try { await apiClient.deployContractV1(parameters as DeployContractV1Request); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, @@ -395,7 +395,7 @@ test(testCase, async (t: Test) => { try { await apiClient.runTransactionV1(parameters as RunTransactionRequest); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, @@ -433,7 +433,7 @@ test(testCase, async (t: Test) => { try { await apiClient.runTransactionV1(parameters as RunTransactionRequest); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, diff --git a/packages/cactus-plugin-ledger-connector-iroha2/src/main/typescript/web-services/generate-transaction-v1-endpoint.ts b/packages/cactus-plugin-ledger-connector-iroha2/src/main/typescript/web-services/generate-transaction-v1-endpoint.ts index 0e374cdab0..fc08a12bb5 100644 --- a/packages/cactus-plugin-ledger-connector-iroha2/src/main/typescript/web-services/generate-transaction-v1-endpoint.ts +++ b/packages/cactus-plugin-ledger-connector-iroha2/src/main/typescript/web-services/generate-transaction-v1-endpoint.ts @@ -16,10 +16,12 @@ import { IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginLedgerConnectorIroha2 } from "../plugin-ledger-connector-iroha2"; -import { safeStringifyException } from "../utils"; import OAS from "../../json/openapi.json"; @@ -29,8 +31,7 @@ export interface IGenerateTransactionOptions { } export class Iroha2GenerateTransactionEndpointV1 - implements IWebServiceEndpoint -{ + implements IWebServiceEndpoint { public static readonly CLASS_NAME = "GenerateTransaction"; private readonly log: Logger; @@ -101,10 +102,8 @@ export class Iroha2GenerateTransactionEndpointV1 res.send(txPayload); } catch (ex) { this.log.warn(`Crash while serving ${reqTag}`, ex); - res.status(500).json({ - message: "Internal Server Error", - error: safeStringifyException(ex), - }); + const errorMsg = "Internal Server Error"; + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-ledger-connector-iroha2/src/main/typescript/web-services/transact-v1-endpoint.ts b/packages/cactus-plugin-ledger-connector-iroha2/src/main/typescript/web-services/transact-v1-endpoint.ts index 6066495d46..41f7f98680 100644 --- a/packages/cactus-plugin-ledger-connector-iroha2/src/main/typescript/web-services/transact-v1-endpoint.ts +++ b/packages/cactus-plugin-ledger-connector-iroha2/src/main/typescript/web-services/transact-v1-endpoint.ts @@ -16,10 +16,12 @@ import { IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginLedgerConnectorIroha2 } from "../plugin-ledger-connector-iroha2"; -import { safeStringifyException } from "../utils"; import OAS from "../../json/openapi.json"; @@ -97,10 +99,8 @@ export class Iroha2TransactEndpointV1 implements IWebServiceEndpoint { res.json(resBody); } catch (ex) { this.log.warn(`Crash while serving ${reqTag}`, ex); - res.status(500).json({ - message: "Internal Server Error", - error: safeStringifyException(ex), - }); + const errorMsg = "Internal Server Error"; + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-ledger-connector-iroha2/src/test/typescript/integration/iroha2-generate-and-send-signed-transaction.test.ts b/packages/cactus-plugin-ledger-connector-iroha2/src/test/typescript/integration/iroha2-generate-and-send-signed-transaction.test.ts index 366c9c69b3..9ac554727b 100644 --- a/packages/cactus-plugin-ledger-connector-iroha2/src/test/typescript/integration/iroha2-generate-and-send-signed-transaction.test.ts +++ b/packages/cactus-plugin-ledger-connector-iroha2/src/test/typescript/integration/iroha2-generate-and-send-signed-transaction.test.ts @@ -31,16 +31,14 @@ import { addRandomSuffix } from "../test-helpers/utils"; import "jest-extended"; import { TransactionPayload } from "@iroha2/data-model"; import { signIrohaV2Query } from "../../../main/typescript/iroha-sign-utils"; -import { AxiosError } from "axios"; -import { ResponseError } from "@iroha2/client"; interface ErrorResponse extends Error { response?: { status?: number; data?: { message: string; - error: any - } + error: any; + }; }; } @@ -336,12 +334,10 @@ describe("Generate and send signed transaction tests", () => { } catch (err) { const errorResponse = err as ErrorResponse; expect(errorResponse?.response?.status).toBe(500); - expect(errorResponse?.response?.data?.message).toEqual("Internal Server Error"); + expect(errorResponse?.response?.data?.message).toEqual( + "Internal Server Error", + ); expect(errorResponse?.response?.data?.error).toBeTruthy(); - - - - } }); @@ -360,10 +356,11 @@ describe("Generate and send signed transaction tests", () => { }); expect(false).toBe(true); // should always throw by now } catch (err) { - const errorResponse = err as ErrorResponse; expect(errorResponse?.response?.status).toBe(500); - expect(errorResponse?.response?.data?.message).toEqual("Internal Server Error"); + expect(errorResponse?.response?.data?.message).toEqual( + "Internal Server Error", + ); expect(errorResponse?.response?.data?.error).toBeTruthy(); } }); diff --git a/packages/cactus-plugin-ledger-connector-polkadot/src/main/typescript/plugin-ledger-connector-polkadot.ts b/packages/cactus-plugin-ledger-connector-polkadot/src/main/typescript/plugin-ledger-connector-polkadot.ts index 9963005c8b..cdab9b5236 100644 --- a/packages/cactus-plugin-ledger-connector-polkadot/src/main/typescript/plugin-ledger-connector-polkadot.ts +++ b/packages/cactus-plugin-ledger-connector-polkadot/src/main/typescript/plugin-ledger-connector-polkadot.ts @@ -101,14 +101,15 @@ export interface IPluginLedgerConnectorPolkadotOptions export class PluginLedgerConnectorPolkadot implements - IPluginLedgerConnector< - DeployContractInkRequest, - DeployContractInkResponse, - RunTransactionRequest, - RunTransactionResponse - >, - ICactusPlugin, - IPluginWebService { + IPluginLedgerConnector< + DeployContractInkRequest, + DeployContractInkResponse, + RunTransactionRequest, + RunTransactionResponse + >, + ICactusPlugin, + IPluginWebService +{ public static readonly CLASS_NAME = "PluginLedgerConnectorPolkadot"; private readonly instanceId: string; private readonly log: Logger; @@ -849,7 +850,7 @@ export class PluginLedgerConnectorPolkadot } catch (err) { throw createHttpError[500]( `${fnTag} Obtaining Prometheus Exporter Metrics has failed. ` + - `InnerException: ${err}`, + `InnerException: ${err}`, ); } } @@ -899,7 +900,7 @@ export class PluginLedgerConnectorPolkadot } catch (err) { throw createHttpError[500]( `${fnTag} Obtaining info for this transaction has failed. ` + - `InnerException: ${err}`, + `InnerException: ${err}`, ); } } diff --git a/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/plugin-ledger-connector-quorum.ts b/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/plugin-ledger-connector-quorum.ts index ce2a0434ae..5f0b33890d 100644 --- a/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/plugin-ledger-connector-quorum.ts +++ b/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/plugin-ledger-connector-quorum.ts @@ -98,14 +98,15 @@ export interface IPluginLedgerConnectorQuorumOptions export class PluginLedgerConnectorQuorum implements - IPluginLedgerConnector< - DeployContractSolidityBytecodeV1Request, - DeployContractSolidityBytecodeV1Response, - RunTransactionRequest, - RunTransactionResponse - >, - ICactusPlugin, - IPluginWebService { + IPluginLedgerConnector< + DeployContractSolidityBytecodeV1Request, + DeployContractSolidityBytecodeV1Response, + RunTransactionRequest, + RunTransactionResponse + >, + ICactusPlugin, + IPluginWebService +{ private readonly pluginRegistry: PluginRegistry; public prometheusExporter: PrometheusExporter; private readonly instanceId: string; @@ -125,17 +126,17 @@ export class PluginLedgerConnectorQuorum if (!this.options.rpcApiWsHost) { return this.options.httpProviderOptions ? new Web3.providers.HttpProvider( - this.options.rpcApiHttpHost, - this.options.httpProviderOptions, - ) + this.options.rpcApiHttpHost, + this.options.httpProviderOptions, + ) : new Web3.providers.HttpProvider(this.options.rpcApiHttpHost); } return this.options.wsProviderOptions ? new Web3.providers.WebsocketProvider( - this.options.rpcApiWsHost, - this.options.wsProviderOptions, - ) + this.options.rpcApiWsHost, + this.options.wsProviderOptions, + ) : new Web3.providers.WebsocketProvider(this.options.rpcApiWsHost); } @@ -524,16 +525,16 @@ export class PluginLedgerConnectorQuorum } else { throw new Error( `${fnTag} Expected pre-signed raw transaction ` + - ` since signing credential is specified as` + - `Web3SigningCredentialType.NONE`, + ` since signing credential is specified as` + + `Web3SigningCredentialType.NONE`, ); } } default: { throw new Error( `${fnTag} Unrecognized Web3SigningCredentialType: ` + - `${req.web3SigningCredential.type} Supported ones are: ` + - `${Object.values(Web3SigningCredentialType).join(";")}`, + `${req.web3SigningCredential.type} Supported ones are: ` + + `${Object.values(Web3SigningCredentialType).join(";")}`, ); } } @@ -576,7 +577,7 @@ export class PluginLedgerConnectorQuorum } catch (ex) { throw new Error( `${fnTag} Failed to invoke web3.eth.personal.sendTransaction(). ` + - `InnerException: ${ex}`, + `InnerException: ${ex}`, ); } } @@ -603,7 +604,7 @@ export class PluginLedgerConnectorQuorum } else { throw new Error( `${fnTag} Failed to sign eth transaction. ` + - `signedTransaction.rawTransaction is blank after .signTransaction().`, + `signedTransaction.rawTransaction is blank after .signTransaction().`, ); } } @@ -923,8 +924,9 @@ export class PluginLedgerConnectorQuorum const isValidType = typeof argValue === input.type; if (!isValidType) { - const msg = `Invalid type for argument ${index + 1} in ${args.contractMethod - }`; + const msg = `Invalid type for argument ${index + 1} in ${ + args.contractMethod + }`; throw new BadRequestError(msg); } }); diff --git a/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/web-services/deploy-contract-solidity-bytecode-endpoint-json-object.ts b/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/web-services/deploy-contract-solidity-bytecode-endpoint-json-object.ts index 4298d019a4..3ba0653b71 100644 --- a/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/web-services/deploy-contract-solidity-bytecode-endpoint-json-object.ts +++ b/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/web-services/deploy-contract-solidity-bytecode-endpoint-json-object.ts @@ -27,7 +27,8 @@ export interface IDeployContractSolidityBytecodeOptionsJsonObject { } export class DeployContractSolidityBytecodeJsonObjectEndpoint - implements IWebServiceEndpoint { + implements IWebServiceEndpoint +{ public static readonly CLASS_NAME = "DeployContractSolidityBytecodeEndpointJsonObject"; @@ -105,5 +106,3 @@ export class DeployContractSolidityBytecodeJsonObjectEndpoint } } } - - diff --git a/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/web-services/get-prometheus-exporter-metrics-endpoint-v1.ts b/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/web-services/get-prometheus-exporter-metrics-endpoint-v1.ts index 20859b205f..ea92ace2a4 100644 --- a/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/web-services/get-prometheus-exporter-metrics-endpoint-v1.ts +++ b/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/web-services/get-prometheus-exporter-metrics-endpoint-v1.ts @@ -27,7 +27,8 @@ export interface IGetPrometheusExporterMetricsEndpointV1Options { } export class GetPrometheusExporterMetricsEndpointV1 - implements IWebServiceEndpoint { + implements IWebServiceEndpoint +{ private readonly log: Logger; constructor( diff --git a/packages/cactus-plugin-ledger-connector-quorum/src/test/typescript/integration/plugin-ledger-connector-quorum/deploy-contract/openapi/openapi-validation-no-keychain.test.ts b/packages/cactus-plugin-ledger-connector-quorum/src/test/typescript/integration/plugin-ledger-connector-quorum/deploy-contract/openapi/openapi-validation-no-keychain.test.ts index c3cabfec5b..06dfb57744 100644 --- a/packages/cactus-plugin-ledger-connector-quorum/src/test/typescript/integration/plugin-ledger-connector-quorum/deploy-contract/openapi/openapi-validation-no-keychain.test.ts +++ b/packages/cactus-plugin-ledger-connector-quorum/src/test/typescript/integration/plugin-ledger-connector-quorum/deploy-contract/openapi/openapi-validation-no-keychain.test.ts @@ -192,7 +192,7 @@ test(testCase, async (t: Test) => { parameters as any as DeployContractSolidityBytecodeJsonObjectV1Request, ); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, @@ -229,7 +229,7 @@ test(testCase, async (t: Test) => { parameters as any as DeployContractSolidityBytecodeJsonObjectV1Request, ); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, @@ -266,7 +266,7 @@ test(testCase, async (t: Test) => { parameters as any as InvokeContractJsonObjectV1Request, ); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, @@ -306,7 +306,7 @@ test(testCase, async (t: Test) => { parameters as any as InvokeContractJsonObjectV1Request, ); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, diff --git a/packages/cactus-plugin-ledger-connector-quorum/src/test/typescript/integration/plugin-ledger-connector-quorum/deploy-contract/openapi/openapi-validation.test.ts b/packages/cactus-plugin-ledger-connector-quorum/src/test/typescript/integration/plugin-ledger-connector-quorum/deploy-contract/openapi/openapi-validation.test.ts index 5c3667a4bd..52d74a2081 100644 --- a/packages/cactus-plugin-ledger-connector-quorum/src/test/typescript/integration/plugin-ledger-connector-quorum/deploy-contract/openapi/openapi-validation.test.ts +++ b/packages/cactus-plugin-ledger-connector-quorum/src/test/typescript/integration/plugin-ledger-connector-quorum/deploy-contract/openapi/openapi-validation.test.ts @@ -181,7 +181,7 @@ test(testCase, async (t: Test) => { parameters as DeployContractSolidityBytecodeV1Request, ); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, @@ -217,7 +217,7 @@ test(testCase, async (t: Test) => { parameters as DeployContractSolidityBytecodeV1Request, ); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, @@ -279,7 +279,7 @@ test(testCase, async (t: Test) => { }; await apiClient.invokeContractV1(parameters as InvokeContractV1Request); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, @@ -318,7 +318,7 @@ test(testCase, async (t: Test) => { }; await apiClient.invokeContractV1(parameters as InvokeContractV1Request); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, @@ -370,7 +370,7 @@ test(testCase, async (t: Test) => { }; await apiClient.runTransactionV1(parameters as RunTransactionRequest); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, @@ -406,7 +406,7 @@ test(testCase, async (t: Test) => { }; await apiClient.runTransactionV1(parameters as RunTransactionRequest); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, diff --git a/packages/cactus-plugin-ledger-connector-sawtooth/src/main/typescript/web-services/status-endpoint-v1.ts b/packages/cactus-plugin-ledger-connector-sawtooth/src/main/typescript/web-services/status-endpoint-v1.ts index 392ad28ae3..90235d6c9e 100644 --- a/packages/cactus-plugin-ledger-connector-sawtooth/src/main/typescript/web-services/status-endpoint-v1.ts +++ b/packages/cactus-plugin-ledger-connector-sawtooth/src/main/typescript/web-services/status-endpoint-v1.ts @@ -8,14 +8,16 @@ import { LogLevelDesc, LoggerProvider, IAsyncProvider, - safeStringifyException, } from "@hyperledger/cactus-common"; import type { IEndpointAuthzOptions, IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import OAS from "../../json/openapi.json"; import { PluginLedgerConnectorSawtooth } from "../plugin-ledger-connector-sawtooth"; @@ -95,10 +97,8 @@ export class StatusEndpointV1 implements IWebServiceEndpoint { res.status(200).json(await this.options.connector.getStatus()); } catch (ex) { this.log.error(`Crash while serving ${reqTag}`, ex); - res.status(500).json({ - message: "Internal Server Error", - error: safeStringifyException(ex), - }); + const errorMsg = "Internal Server Error"; + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-ledger-connector-xdai/src/main/typescript/web-services/deploy-contract-solidity-bytecode-endpoint.ts b/packages/cactus-plugin-ledger-connector-xdai/src/main/typescript/web-services/deploy-contract-solidity-bytecode-endpoint.ts index fd58762a5f..34c176cfb9 100644 --- a/packages/cactus-plugin-ledger-connector-xdai/src/main/typescript/web-services/deploy-contract-solidity-bytecode-endpoint.ts +++ b/packages/cactus-plugin-ledger-connector-xdai/src/main/typescript/web-services/deploy-contract-solidity-bytecode-endpoint.ts @@ -27,7 +27,8 @@ export interface IDeployContractSolidityBytecodeOptions { } export class DeployContractSolidityBytecodeEndpoint - implements IWebServiceEndpoint { + implements IWebServiceEndpoint +{ public static readonly CLASS_NAME = "DeployContractSolidityBytecodeEndpoint"; private readonly log: Logger; diff --git a/packages/cactus-plugin-ledger-connector-xdai/src/main/typescript/web-services/deploy-contract-solidity-bytecode-json-object-endpoint.ts b/packages/cactus-plugin-ledger-connector-xdai/src/main/typescript/web-services/deploy-contract-solidity-bytecode-json-object-endpoint.ts index c34b60ebdc..d7af23d453 100644 --- a/packages/cactus-plugin-ledger-connector-xdai/src/main/typescript/web-services/deploy-contract-solidity-bytecode-json-object-endpoint.ts +++ b/packages/cactus-plugin-ledger-connector-xdai/src/main/typescript/web-services/deploy-contract-solidity-bytecode-json-object-endpoint.ts @@ -27,7 +27,8 @@ export interface IDeployContractSolidityBytecodeJsonObjectOptions { } export class DeployContractSolidityBytecodeJsonObjectEndpoint - implements IWebServiceEndpoint { + implements IWebServiceEndpoint +{ public static readonly CLASS_NAME = "DeployContractSolidityBytecodeJsonObjectEndpoint"; diff --git a/packages/cactus-plugin-ledger-connector-xdai/src/main/typescript/web-services/get-prometheus-exporter-metrics-endpoint-v1.ts b/packages/cactus-plugin-ledger-connector-xdai/src/main/typescript/web-services/get-prometheus-exporter-metrics-endpoint-v1.ts index 2c2409f8c3..cac1673091 100644 --- a/packages/cactus-plugin-ledger-connector-xdai/src/main/typescript/web-services/get-prometheus-exporter-metrics-endpoint-v1.ts +++ b/packages/cactus-plugin-ledger-connector-xdai/src/main/typescript/web-services/get-prometheus-exporter-metrics-endpoint-v1.ts @@ -27,7 +27,8 @@ export interface IGetPrometheusExporterMetricsEndpointV1Options { } export class GetPrometheusExporterMetricsEndpointV1 - implements IWebServiceEndpoint { + implements IWebServiceEndpoint +{ private readonly log: Logger; constructor( diff --git a/packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/invoke-contract-xdai.test.ts b/packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/invoke-contract-xdai.test.ts index a38f1dea2b..bb5c345264 100644 --- a/packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/invoke-contract-xdai.test.ts +++ b/packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/invoke-contract-xdai.test.ts @@ -311,7 +311,7 @@ describe(testCase, () => { if (error instanceof Error) { expect(error.message).toContain( "Transaction with the same hash was already imported", - ) + ); } else { console.error("Unexpected error type:", error); } diff --git a/packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/openapi/openapi-validation-no-keychain.test.ts b/packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/openapi/openapi-validation-no-keychain.test.ts index 36a2da00cd..33fc6faed3 100644 --- a/packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/openapi/openapi-validation-no-keychain.test.ts +++ b/packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/openapi/openapi-validation-no-keychain.test.ts @@ -143,7 +143,7 @@ test(testCase, async (t: Test) => { parameters as any as DeployContractJsonObjectV1Request, ); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, @@ -178,14 +178,15 @@ test(testCase, async (t: Test) => { parameters as any as DeployContractJsonObjectV1Request, ); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, t2.equal( e?.response?.status, 400, `Endpoint ${fDeploy} with fake=4: response.status === 400 OK`, - )); + ), + ); const fields = e?.response?.data.map((param: any) => param.path.replace("/body/", ""), ); @@ -242,15 +243,15 @@ test(testCase, async (t: Test) => { parameters as any as InvokeContractJsonObjectV1Request, ); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, t2.equal( e?.response?.status, 400, `Endpoint ${fInvoke} without required contractJSON: response.status === 400 OK`, - ) - ) + ), + ); const fields = e?.response?.data.map((param: any) => param.path.replace("/body/", ""), ); @@ -283,14 +284,15 @@ test(testCase, async (t: Test) => { parameters as any as InvokeContractJsonObjectV1Request, ); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, t2.equal( e?.response?.status, 400, `Endpoint ${fInvoke} with fake=4: response.status === 400 OK`, - )) + ), + ); const fields = e?.response?.data.map((param: any) => param.path.replace("/body/", ""), ); diff --git a/packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/openapi/openapi-validation.test.ts b/packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/openapi/openapi-validation.test.ts index 0fef7d44f6..e863af17ab 100644 --- a/packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/openapi/openapi-validation.test.ts +++ b/packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/openapi/openapi-validation.test.ts @@ -167,7 +167,7 @@ test(testCase, async (t: Test) => { parameters as unknown as DeployContractV1Request, ); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, @@ -201,7 +201,7 @@ test(testCase, async (t: Test) => { }; await apiClient.deployContractV1(parameters); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, @@ -263,7 +263,7 @@ test(testCase, async (t: Test) => { parameters as unknown as InvokeContractV1Request, ); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, @@ -301,7 +301,7 @@ test(testCase, async (t: Test) => { parameters as any as InvokeContractV1Request, ); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, @@ -365,7 +365,7 @@ test(testCase, async (t: Test) => { parameters as any as RunTransactionV1Request, ); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, @@ -408,7 +408,7 @@ test(testCase, async (t: Test) => { parameters as any as RunTransactionV1Request, ); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, diff --git a/packages/cactus-plugin-persistence-ethereum/src/main/typescript/web-services/status-endpoint-v1.ts b/packages/cactus-plugin-persistence-ethereum/src/main/typescript/web-services/status-endpoint-v1.ts index 66a1d78358..7f1c43b0a9 100644 --- a/packages/cactus-plugin-persistence-ethereum/src/main/typescript/web-services/status-endpoint-v1.ts +++ b/packages/cactus-plugin-persistence-ethereum/src/main/typescript/web-services/status-endpoint-v1.ts @@ -8,14 +8,16 @@ import { LogLevelDesc, LoggerProvider, IAsyncProvider, - safeStringifyException, } from "@hyperledger/cactus-common"; import type { IEndpointAuthzOptions, IExpressRequestHandler, IWebServiceEndpoint, } from "@hyperledger/cactus-core-api"; -import { registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginPersistenceEthereum } from "../plugin-persistence-ethereum"; import OAS from "../../json/openapi.json"; @@ -99,10 +101,8 @@ export class StatusEndpointV1 implements IWebServiceEndpoint { res.status(200).json(resBody); } catch (ex) { this.log.warn(`Crash while serving ${reqTag}`, ex); - res.status(500).json({ - message: "Internal Server Error", - error: safeStringifyException(ex), - }); + const errorMsg = "Internal Server Error"; + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); } } } diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/client-side/client-request-endpoint.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/client-side/client-request-endpoint.ts index 74606af096..65217620e9 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/client-side/client-request-endpoint.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/client-side/client-request-endpoint.ts @@ -13,7 +13,10 @@ import { IAsyncProvider, } from "@hyperledger/cactus-common"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginSatpGateway } from "../../gateway/plugin-satp-gateway"; @@ -93,7 +96,6 @@ export class ClientRequestEndpointV1 implements IWebServiceEndpoint { this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `${fnTag} request handler fn crashed for: ${reqTag}`; handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); - } } } diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/client-side/commit-final-response-endpoint.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/client-side/commit-final-response-endpoint.ts index 38f93a2f80..1fbccf94d8 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/client-side/commit-final-response-endpoint.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/client-side/commit-final-response-endpoint.ts @@ -13,7 +13,10 @@ import { IAsyncProvider, } from "@hyperledger/cactus-common"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginSatpGateway } from "../../gateway/plugin-satp-gateway"; @@ -46,7 +49,7 @@ export class CommitFinalResponseEndpointV1 implements IWebServiceEndpoint { public getPath(): string { const apiPath = OAS.paths[ - "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase3/commitfinalresponse" + "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase3/commitfinalresponse" ]; return apiPath.post["x-hyperledger-cacti"].http.path; } @@ -54,7 +57,7 @@ export class CommitFinalResponseEndpointV1 implements IWebServiceEndpoint { public getVerbLowerCase(): string { const apiPath = OAS.paths[ - "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase3/commitfinalresponse" + "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase3/commitfinalresponse" ]; return apiPath.post["x-hyperledger-cacti"].http.verbLowerCase; } @@ -97,7 +100,6 @@ export class CommitFinalResponseEndpointV1 implements IWebServiceEndpoint { this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `${fnTag} request handler fn crashed for: ${reqTag}`; handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); - } } } diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/client-side/commit-prepare-response-endpoint.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/client-side/commit-prepare-response-endpoint.ts index ecbf47dc84..0ff8fb58e5 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/client-side/commit-prepare-response-endpoint.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/client-side/commit-prepare-response-endpoint.ts @@ -13,7 +13,10 @@ import { IAsyncProvider, } from "@hyperledger/cactus-common"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginSatpGateway } from "../../gateway/plugin-satp-gateway"; @@ -25,7 +28,8 @@ export interface ICommitPreparationResponseEndpointOptions { } export class CommitPreparationResponseEndpointV1 - implements IWebServiceEndpoint { + implements IWebServiceEndpoint +{ public static readonly CLASS_NAME = "CommitPrepareResponseEndpointV1"; private readonly log: Logger; @@ -49,7 +53,7 @@ export class CommitPreparationResponseEndpointV1 public getPath(): string { const apiPath = OAS.paths[ - "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase3/commitpreparationresponse" + "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase3/commitpreparationresponse" ]; return apiPath.post["x-hyperledger-cacti"].http.path; } @@ -57,7 +61,7 @@ export class CommitPreparationResponseEndpointV1 public getVerbLowerCase(): string { const apiPath = OAS.paths[ - "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase3/commitpreparationresponse" + "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase3/commitpreparationresponse" ]; return apiPath.post["x-hyperledger-cacti"].http.verbLowerCase; } @@ -100,7 +104,6 @@ export class CommitPreparationResponseEndpointV1 this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `${fnTag} request handler fn crashed for: ${reqTag}`; handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); - } } } diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/client-side/lock-evidence-response-endpoint.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/client-side/lock-evidence-response-endpoint.ts index 02e99ca813..4cd86ca9b4 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/client-side/lock-evidence-response-endpoint.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/client-side/lock-evidence-response-endpoint.ts @@ -13,7 +13,10 @@ import { IAsyncProvider, } from "@hyperledger/cactus-common"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginSatpGateway } from "../../gateway/plugin-satp-gateway"; import OAS from "../../../json/openapi.json"; @@ -49,7 +52,7 @@ export class LockEvidenceResponseEndpointV1 implements IWebServiceEndpoint { public getPath(): string { const apiPath = OAS.paths[ - "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase2/lockevidenceresponse" + "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase2/lockevidenceresponse" ]; return apiPath.post["x-hyperledger-cacti"].http.path; } @@ -57,7 +60,7 @@ export class LockEvidenceResponseEndpointV1 implements IWebServiceEndpoint { public getVerbLowerCase(): string { const apiPath = OAS.paths[ - "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase2/lockevidenceresponse" + "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase2/lockevidenceresponse" ]; return apiPath.post["x-hyperledger-cacti"].http.verbLowerCase; } @@ -100,7 +103,6 @@ export class LockEvidenceResponseEndpointV1 implements IWebServiceEndpoint { this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `${fnTag} request handler fn crashed for: ${reqTag}`; handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); - } } -} \ No newline at end of file +} diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/client-side/transfer-commence-response-endpoint.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/client-side/transfer-commence-response-endpoint.ts index a4dccec890..998d397f30 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/client-side/transfer-commence-response-endpoint.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/client-side/transfer-commence-response-endpoint.ts @@ -13,7 +13,10 @@ import { IAsyncProvider, } from "@hyperledger/cactus-common"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginSatpGateway } from "../../gateway/plugin-satp-gateway"; import OAS from "../../../json/openapi.json"; @@ -47,7 +50,7 @@ export class TransferCommenceResponseEndpointV1 implements IWebServiceEndpoint { public getPath(): string { const apiPath = OAS.paths[ - "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase2/transfercommenceresponse" + "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase2/transfercommenceresponse" ]; return apiPath.post["x-hyperledger-cacti"].http.path; } @@ -55,7 +58,7 @@ export class TransferCommenceResponseEndpointV1 implements IWebServiceEndpoint { public getVerbLowerCase(): string { const apiPath = OAS.paths[ - "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase2/transfercommenceresponse" + "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase2/transfercommenceresponse" ]; return apiPath.post["x-hyperledger-cacti"].http.verbLowerCase; } @@ -98,7 +101,6 @@ export class TransferCommenceResponseEndpointV1 implements IWebServiceEndpoint { this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `${fnTag} request handler fn crashed for: ${reqTag}`; handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); - } } } diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/client-side/transfer-initiation-response-endpoint.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/client-side/transfer-initiation-response-endpoint.ts index 9ec15246f2..4f48db4af1 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/client-side/transfer-initiation-response-endpoint.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/client-side/transfer-initiation-response-endpoint.ts @@ -13,7 +13,10 @@ import { IAsyncProvider, } from "@hyperledger/cactus-common"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginSatpGateway } from "../../gateway/plugin-satp-gateway"; import OAS from "../../../json/openapi.json"; @@ -24,7 +27,8 @@ export interface ITransferInitiationResponseEndpointOptions { } export class TransferInitiationResponseEndpointV1 - implements IWebServiceEndpoint { + implements IWebServiceEndpoint +{ public static readonly CLASS_NAME = "TransferInitiationResponseEndpointV1"; private readonly log: Logger; @@ -48,7 +52,7 @@ export class TransferInitiationResponseEndpointV1 public getPath(): string { const apiPath = OAS.paths[ - "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase1/transferinitiationresponse" + "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase1/transferinitiationresponse" ]; return apiPath.post["x-hyperledger-cacti"].http.path; } @@ -56,7 +60,7 @@ export class TransferInitiationResponseEndpointV1 public getVerbLowerCase(): string { const apiPath = OAS.paths[ - "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase1/transferinitiationresponse" + "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase1/transferinitiationresponse" ]; return apiPath.post["x-hyperledger-cacti"].http.verbLowerCase; } @@ -100,7 +104,6 @@ export class TransferInitiationResponseEndpointV1 this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `${fnTag} request handler fn crashed for: ${reqTag}`; handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); - } } } diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/recovery/recover-message-endpoint.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/recovery/recover-message-endpoint.ts index c187d86545..6c9d62f773 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/recovery/recover-message-endpoint.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/recovery/recover-message-endpoint.ts @@ -13,7 +13,10 @@ import { IAsyncProvider, } from "@hyperledger/cactus-common"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginSatpGateway } from "../../gateway/plugin-satp-gateway"; @@ -46,7 +49,7 @@ export class RecoverMessageEndpointV1 implements IWebServiceEndpoint { public getPath(): string { const apiPath = OAS.paths[ - "/api/v1/@hyperledger/cactus-plugin-satp-hermes/recovermessage" + "/api/v1/@hyperledger/cactus-plugin-satp-hermes/recovermessage" ]; return apiPath.post["x-hyperledger-cacti"].http.path; } @@ -54,7 +57,7 @@ export class RecoverMessageEndpointV1 implements IWebServiceEndpoint { public getVerbLowerCase(): string { const apiPath = OAS.paths[ - "/api/v1/@hyperledger/cactus-plugin-satp-hermes/recovermessage" + "/api/v1/@hyperledger/cactus-plugin-satp-hermes/recovermessage" ]; return apiPath.post["x-hyperledger-cacti"].http.verbLowerCase; } @@ -97,7 +100,6 @@ export class RecoverMessageEndpointV1 implements IWebServiceEndpoint { this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `${fnTag} request handler fn crashed for: ${reqTag}`; handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); - } } } diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/recovery/recover-success-message-endpoint.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/recovery/recover-success-message-endpoint.ts index 0ffcb2376e..5a61fc0e37 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/recovery/recover-success-message-endpoint.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/recovery/recover-success-message-endpoint.ts @@ -13,7 +13,10 @@ import { IAsyncProvider, } from "@hyperledger/cactus-common"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginSatpGateway } from "../../gateway/plugin-satp-gateway"; @@ -46,7 +49,7 @@ export class RecoverSuccessMessageEndpointV1 implements IWebServiceEndpoint { public getPath(): string { const apiPath = OAS.paths[ - "/api/v1/@hyperledger/cactus-plugin-satp-hermes/recoversuccessmessage" + "/api/v1/@hyperledger/cactus-plugin-satp-hermes/recoversuccessmessage" ]; return apiPath.post["x-hyperledger-cacti"].http.path; } @@ -54,7 +57,7 @@ export class RecoverSuccessMessageEndpointV1 implements IWebServiceEndpoint { public getVerbLowerCase(): string { const apiPath = OAS.paths[ - "/api/v1/@hyperledger/cactus-plugin-satp-hermes/recoversuccessmessage" + "/api/v1/@hyperledger/cactus-plugin-satp-hermes/recoversuccessmessage" ]; return apiPath.post["x-hyperledger-cacti"].http.verbLowerCase; } @@ -98,7 +101,6 @@ export class RecoverSuccessMessageEndpointV1 implements IWebServiceEndpoint { this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `${fnTag} request handler fn crashed for: ${reqTag}`; handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); - } } } diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/recovery/recover-update-ack-message-endpoint.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/recovery/recover-update-ack-message-endpoint.ts index 1c3e4d7840..cd2b346aca 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/recovery/recover-update-ack-message-endpoint.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/recovery/recover-update-ack-message-endpoint.ts @@ -13,7 +13,10 @@ import { IAsyncProvider, } from "@hyperledger/cactus-common"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginSatpGateway } from "../../gateway/plugin-satp-gateway"; @@ -48,7 +51,7 @@ export class RecoverUpdateAckMessageEndpointV1 implements IWebServiceEndpoint { public getPath(): string { const apiPath = OAS.paths[ - "/api/v1/@hyperledger/cactus-plugin-satp-hermes/recoverupdateackmessage" + "/api/v1/@hyperledger/cactus-plugin-satp-hermes/recoverupdateackmessage" ]; return apiPath.post["x-hyperledger-cacti"].http.path; } @@ -56,7 +59,7 @@ export class RecoverUpdateAckMessageEndpointV1 implements IWebServiceEndpoint { public getVerbLowerCase(): string { const apiPath = OAS.paths[ - "/api/v1/@hyperledger/cactus-plugin-satp-hermes/recoverupdateackmessage" + "/api/v1/@hyperledger/cactus-plugin-satp-hermes/recoverupdateackmessage" ]; return apiPath.post["x-hyperledger-cacti"].http.verbLowerCase; } @@ -99,7 +102,6 @@ export class RecoverUpdateAckMessageEndpointV1 implements IWebServiceEndpoint { this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `${fnTag} request handler fn crashed for: ${reqTag}`; handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); - } } } diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/recovery/recover-update-message-endpoint.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/recovery/recover-update-message-endpoint.ts index 6860fcd058..a8111b9aa8 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/recovery/recover-update-message-endpoint.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/recovery/recover-update-message-endpoint.ts @@ -13,7 +13,10 @@ import { IAsyncProvider, } from "@hyperledger/cactus-common"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginSatpGateway } from "../../gateway/plugin-satp-gateway"; @@ -46,7 +49,7 @@ export class RecoverUpdateMessageEndpointV1 implements IWebServiceEndpoint { public getPath(): string { const apiPath = OAS.paths[ - "/api/v1/@hyperledger/cactus-plugin-satp-hermes/recoverupdatemessage" + "/api/v1/@hyperledger/cactus-plugin-satp-hermes/recoverupdatemessage" ]; return apiPath.post["x-hyperledger-cacti"].http.path; } @@ -54,7 +57,7 @@ export class RecoverUpdateMessageEndpointV1 implements IWebServiceEndpoint { public getVerbLowerCase(): string { const apiPath = OAS.paths[ - "/api/v1/@hyperledger/cactus-plugin-satp-hermes/recoverupdatemessage" + "/api/v1/@hyperledger/cactus-plugin-satp-hermes/recoverupdatemessage" ]; return apiPath.post["x-hyperledger-cacti"].http.verbLowerCase; } @@ -97,7 +100,6 @@ export class RecoverUpdateMessageEndpointV1 implements IWebServiceEndpoint { this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `${fnTag} request handler fn crashed for: ${reqTag}`; handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); - } } } diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/recovery/rollback-ack-message-endpoint.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/recovery/rollback-ack-message-endpoint.ts index fa865fb16a..703424caf7 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/recovery/rollback-ack-message-endpoint.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/recovery/rollback-ack-message-endpoint.ts @@ -13,7 +13,10 @@ import { IAsyncProvider, } from "@hyperledger/cactus-common"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginSatpGateway } from "../../gateway/plugin-satp-gateway"; @@ -46,7 +49,7 @@ export class RollbackAckMessageEndpointV1 implements IWebServiceEndpoint { public getPath(): string { const apiPath = OAS.paths[ - "/api/v1/@hyperledger/cactus-plugin-satp-hermes/rollbackackmessage" + "/api/v1/@hyperledger/cactus-plugin-satp-hermes/rollbackackmessage" ]; return apiPath.post["x-hyperledger-cacti"].http.path; } @@ -54,7 +57,7 @@ export class RollbackAckMessageEndpointV1 implements IWebServiceEndpoint { public getVerbLowerCase(): string { const apiPath = OAS.paths[ - "/api/v1/@hyperledger/cactus-plugin-satp-hermes/rollbackackmessage" + "/api/v1/@hyperledger/cactus-plugin-satp-hermes/rollbackackmessage" ]; return apiPath.post["x-hyperledger-cacti"].http.verbLowerCase; } @@ -98,7 +101,6 @@ export class RollbackAckMessageEndpointV1 implements IWebServiceEndpoint { this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `${fnTag} request handler fn crashed for: ${reqTag}`; handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); - } } } diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/recovery/rollback-message-endpoint.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/recovery/rollback-message-endpoint.ts index 07b644b088..5fb33612e7 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/recovery/rollback-message-endpoint.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/recovery/rollback-message-endpoint.ts @@ -13,7 +13,10 @@ import { IAsyncProvider, } from "@hyperledger/cactus-common"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginSatpGateway } from "../../gateway/plugin-satp-gateway"; @@ -46,7 +49,7 @@ export class RollbackMessageEndpointV1 implements IWebServiceEndpoint { public getPath(): string { const apiPath = OAS.paths[ - "/api/v1/@hyperledger/cactus-plugin-satp-hermes/rollbackmessage" + "/api/v1/@hyperledger/cactus-plugin-satp-hermes/rollbackmessage" ]; return apiPath.post["x-hyperledger-cacti"].http.path; } @@ -54,7 +57,7 @@ export class RollbackMessageEndpointV1 implements IWebServiceEndpoint { public getVerbLowerCase(): string { const apiPath = OAS.paths[ - "/api/v1/@hyperledger/cactus-plugin-satp-hermes/rollbackmessage" + "/api/v1/@hyperledger/cactus-plugin-satp-hermes/rollbackmessage" ]; return apiPath.post["x-hyperledger-cacti"].http.verbLowerCase; } @@ -98,7 +101,6 @@ export class RollbackMessageEndpointV1 implements IWebServiceEndpoint { this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `${fnTag} request handler fn crashed for: ${reqTag}`; handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); - } } } diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/server-side/commit-final-request-endpoint.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/server-side/commit-final-request-endpoint.ts index dcaa0dfe0e..7fd7b4974b 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/server-side/commit-final-request-endpoint.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/server-side/commit-final-request-endpoint.ts @@ -13,7 +13,10 @@ import { IAsyncProvider, } from "@hyperledger/cactus-common"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginSatpGateway } from "../../gateway/plugin-satp-gateway"; import OAS from "../../../json/openapi.json"; @@ -45,7 +48,7 @@ export class CommitFinalRequestEndpointV1 implements IWebServiceEndpoint { public getPath(): string { const apiPath = OAS.paths[ - "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase3/commitfinalrequest" + "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase3/commitfinalrequest" ]; return apiPath.post["x-hyperledger-cacti"].http.path; } @@ -53,7 +56,7 @@ export class CommitFinalRequestEndpointV1 implements IWebServiceEndpoint { public getVerbLowerCase(): string { const apiPath = OAS.paths[ - "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase3/commitfinalrequest" + "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase3/commitfinalrequest" ]; return apiPath.post["x-hyperledger-cacti"].http.verbLowerCase; } @@ -96,7 +99,6 @@ export class CommitFinalRequestEndpointV1 implements IWebServiceEndpoint { this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `${fnTag} request handler fn crashed for: ${reqTag}`; handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); - } } } diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/server-side/commite-prepare-request-endpoint.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/server-side/commite-prepare-request-endpoint.ts index 70719a283b..764594fc53 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/server-side/commite-prepare-request-endpoint.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/server-side/commite-prepare-request-endpoint.ts @@ -13,7 +13,10 @@ import { IAsyncProvider, } from "@hyperledger/cactus-common"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginSatpGateway } from "../../gateway/plugin-satp-gateway"; import OAS from "../../../json/openapi.json"; @@ -47,7 +50,7 @@ export class CommitPreparationRequestEndpointV1 implements IWebServiceEndpoint { public getPath(): string { const apiPath = OAS.paths[ - "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase3/commitpreparationrequest" + "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase3/commitpreparationrequest" ]; return apiPath.post["x-hyperledger-cacti"].http.path; } @@ -55,7 +58,7 @@ export class CommitPreparationRequestEndpointV1 implements IWebServiceEndpoint { public getVerbLowerCase(): string { const apiPath = OAS.paths[ - "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase3/commitpreparationrequest" + "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase3/commitpreparationrequest" ]; return apiPath.post["x-hyperledger-cacti"].http.verbLowerCase; } @@ -98,7 +101,6 @@ export class CommitPreparationRequestEndpointV1 implements IWebServiceEndpoint { this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `${fnTag} request handler fn crashed for: ${reqTag}`; handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); - } } } diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/server-side/lock-evidence-request-endpoint.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/server-side/lock-evidence-request-endpoint.ts index 0712daf790..85859e74b0 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/server-side/lock-evidence-request-endpoint.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/server-side/lock-evidence-request-endpoint.ts @@ -13,7 +13,10 @@ import { IAsyncProvider, } from "@hyperledger/cactus-common"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginSatpGateway } from "../../gateway/plugin-satp-gateway"; import OAS from "../../../json/openapi.json"; @@ -49,7 +52,7 @@ export class LockEvidenceRequestEndpointV1 implements IWebServiceEndpoint { public getPath(): string { const apiPath = OAS.paths[ - "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase2/lockevidencerequest" + "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase2/lockevidencerequest" ]; return apiPath.post["x-hyperledger-cacti"].http.path; } @@ -57,7 +60,7 @@ export class LockEvidenceRequestEndpointV1 implements IWebServiceEndpoint { public getVerbLowerCase(): string { const apiPath = OAS.paths[ - "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase2/lockevidencerequest" + "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase2/lockevidencerequest" ]; return apiPath.post["x-hyperledger-cacti"].http.verbLowerCase; } @@ -100,7 +103,6 @@ export class LockEvidenceRequestEndpointV1 implements IWebServiceEndpoint { this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `${fnTag} request handler fn crashed for: ${reqTag}`; handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); - } } } diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/server-side/transfer-commence-request-endpoint.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/server-side/transfer-commence-request-endpoint.ts index cba3d9a490..f1d48f9799 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/server-side/transfer-commence-request-endpoint.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/server-side/transfer-commence-request-endpoint.ts @@ -13,7 +13,10 @@ import { IAsyncProvider, } from "@hyperledger/cactus-common"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginSatpGateway } from "../../gateway/plugin-satp-gateway"; import OAS from "../../../json/openapi.json"; @@ -47,7 +50,7 @@ export class TransferCommenceRequestEndpointV1 implements IWebServiceEndpoint { public getPath(): string { const apiPath = OAS.paths[ - "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase2/transfercommencerequest" + "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase2/transfercommencerequest" ]; return apiPath.post["x-hyperledger-cacti"].http.path; } @@ -55,7 +58,7 @@ export class TransferCommenceRequestEndpointV1 implements IWebServiceEndpoint { public getVerbLowerCase(): string { const apiPath = OAS.paths[ - "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase2/transfercommencerequest" + "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase2/transfercommencerequest" ]; return apiPath.post["x-hyperledger-cacti"].http.verbLowerCase; } @@ -98,7 +101,6 @@ export class TransferCommenceRequestEndpointV1 implements IWebServiceEndpoint { this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `${fnTag} request handler fn crashed for: ${reqTag}`; handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); - } } } diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/server-side/transfer-complete-request-endpoint.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/server-side/transfer-complete-request-endpoint.ts index 2a160ec8ba..42922af1ff 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/server-side/transfer-complete-request-endpoint.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/server-side/transfer-complete-request-endpoint.ts @@ -13,7 +13,10 @@ import { IAsyncProvider, } from "@hyperledger/cactus-common"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginSatpGateway } from "../../gateway/plugin-satp-gateway"; import OAS from "../../../json/openapi.json"; @@ -47,7 +50,7 @@ export class TransferCompleteRequestEndpointV1 implements IWebServiceEndpoint { public getPath(): string { const apiPath = OAS.paths[ - "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase3/transfercompleterequest" + "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase3/transfercompleterequest" ]; return apiPath.get["x-hyperledger-cacti"].http.path; } @@ -55,7 +58,7 @@ export class TransferCompleteRequestEndpointV1 implements IWebServiceEndpoint { public getVerbLowerCase(): string { const apiPath = OAS.paths[ - "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase3/transfercompleterequest" + "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase3/transfercompleterequest" ]; return apiPath.get["x-hyperledger-cacti"].http.verbLowerCase; } @@ -98,7 +101,6 @@ export class TransferCompleteRequestEndpointV1 implements IWebServiceEndpoint { this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `${fnTag} request handler fn crashed for: ${reqTag}`; handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); - } } } diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/server-side/transfer-initiation-request-endpoint.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/server-side/transfer-initiation-request-endpoint.ts index 4b59a5d6b0..deedd3d8aa 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/server-side/transfer-initiation-request-endpoint.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/web-services/server-side/transfer-initiation-request-endpoint.ts @@ -13,7 +13,10 @@ import { IAsyncProvider, } from "@hyperledger/cactus-common"; -import { handleRestEndpointException, registerWebServiceEndpoint } from "@hyperledger/cactus-core"; +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; import { PluginSatpGateway } from "../../gateway/plugin-satp-gateway"; import OAS from "../../../json/openapi.json"; @@ -24,7 +27,8 @@ export interface ITransferInitiationRequestEndpointOptions { } export class TransferInitiationRequestEndpointV1 - implements IWebServiceEndpoint { + implements IWebServiceEndpoint +{ public static readonly CLASS_NAME = "TransferInitiationRequestEndpointV1"; private readonly log: Logger; @@ -48,7 +52,7 @@ export class TransferInitiationRequestEndpointV1 public getPath(): string { const apiPath = OAS.paths[ - "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase1/transferinitiationrequest" + "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase1/transferinitiationrequest" ]; return apiPath.post["x-hyperledger-cacti"].http.path; } @@ -56,7 +60,7 @@ export class TransferInitiationRequestEndpointV1 public getVerbLowerCase(): string { const apiPath = OAS.paths[ - "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase1/transferinitiationrequest" + "/api/v1/@hyperledger/cactus-plugin-satp-hermes/phase1/transferinitiationrequest" ]; return apiPath.post["x-hyperledger-cacti"].http.verbLowerCase; } @@ -100,7 +104,6 @@ export class TransferInitiationRequestEndpointV1 this.log.error(`Crash while serving ${reqTag}`, ex); const errorMsg = `${fnTag} request handler fn crashed for: ${reqTag}`; handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); - } } } diff --git a/packages/cactus-test-plugin-consortium-manual/src/test/typescript/integration/plugin-consortium-manual/openapi/openapi-validation.test.ts b/packages/cactus-test-plugin-consortium-manual/src/test/typescript/integration/plugin-consortium-manual/openapi/openapi-validation.test.ts index afcdc61f73..2c6ec3caff 100644 --- a/packages/cactus-test-plugin-consortium-manual/src/test/typescript/integration/plugin-consortium-manual/openapi/openapi-validation.test.ts +++ b/packages/cactus-test-plugin-consortium-manual/src/test/typescript/integration/plugin-consortium-manual/openapi/openapi-validation.test.ts @@ -289,7 +289,7 @@ test(testCase, async (t: Test) => { try { await api.getNodeJwsV1({ fake: 4 }); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, @@ -313,7 +313,7 @@ test(testCase, async (t: Test) => { try { await api.getConsortiumJwsV1({ fake: 4 }); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, diff --git a/packages/cactus-test-plugin-htlc-eth-besu-erc20/src/test/typescript/integration/plugin-htlc-eth-besu-erc20/initialize-endpoint.test.ts b/packages/cactus-test-plugin-htlc-eth-besu-erc20/src/test/typescript/integration/plugin-htlc-eth-besu-erc20/initialize-endpoint.test.ts index 18dfd66530..927265faef 100644 --- a/packages/cactus-test-plugin-htlc-eth-besu-erc20/src/test/typescript/integration/plugin-htlc-eth-besu-erc20/initialize-endpoint.test.ts +++ b/packages/cactus-test-plugin-htlc-eth-besu-erc20/src/test/typescript/integration/plugin-htlc-eth-besu-erc20/initialize-endpoint.test.ts @@ -205,7 +205,7 @@ describe(testCase, () => { const res = await api.initializeV1(request); expect(res.status).toEqual(400); } catch (err) { - const e = err as AxiosError + const e = err as AxiosError; expect(e?.response?.status).toEqual(400); } }); diff --git a/packages/cactus-test-plugin-htlc-eth-besu-erc20/src/test/typescript/integration/plugin-htlc-eth-besu-erc20/new-contract-endpoint.test.ts b/packages/cactus-test-plugin-htlc-eth-besu-erc20/src/test/typescript/integration/plugin-htlc-eth-besu-erc20/new-contract-endpoint.test.ts index c5dafa78a5..8e2c80b39f 100644 --- a/packages/cactus-test-plugin-htlc-eth-besu-erc20/src/test/typescript/integration/plugin-htlc-eth-besu-erc20/new-contract-endpoint.test.ts +++ b/packages/cactus-test-plugin-htlc-eth-besu-erc20/src/test/typescript/integration/plugin-htlc-eth-besu-erc20/new-contract-endpoint.test.ts @@ -332,7 +332,7 @@ describe(testCase, () => { const res = await api.newContractV1(request); expect(res.status).toEqual(400); } catch (err) { - const e = err as AxiosError + const e = err as AxiosError; expect(e?.response?.status).toEqual(400); } }); diff --git a/packages/cactus-test-plugin-htlc-eth-besu-erc20/src/test/typescript/integration/plugin-htlc-eth-besu-erc20/openapi/openapi-validation.test.ts b/packages/cactus-test-plugin-htlc-eth-besu-erc20/src/test/typescript/integration/plugin-htlc-eth-besu-erc20/openapi/openapi-validation.test.ts index b18e282128..2392b4aca3 100644 --- a/packages/cactus-test-plugin-htlc-eth-besu-erc20/src/test/typescript/integration/plugin-htlc-eth-besu-erc20/openapi/openapi-validation.test.ts +++ b/packages/cactus-test-plugin-htlc-eth-besu-erc20/src/test/typescript/integration/plugin-htlc-eth-besu-erc20/openapi/openapi-validation.test.ts @@ -219,11 +219,11 @@ test(testCase, async (t: Test) => { try { await api.initializeV1(parameters as any as InitializeRequest); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, - `Endpoint ${fInitialize} waithout required connectorId: response.status === 400 OK`, + `Endpoint ${fInitialize} without required connectorId: response.status === 400 OK`, ); const fields = e?.response?.data.map((param: any) => param.path.replace("/body/", ""), @@ -249,7 +249,7 @@ test(testCase, async (t: Test) => { try { await api.initializeV1(parameters as any as InitializeRequest); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, @@ -364,7 +364,7 @@ test(testCase, async (t: Test) => { try { await api.newContractV1(parameters as any as NewContractRequest); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, @@ -402,7 +402,7 @@ test(testCase, async (t: Test) => { try { await api.newContractV1(parameters as any as NewContractRequest); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, @@ -467,7 +467,7 @@ test(testCase, async (t: Test) => { try { await api.refundV1(parameters as any as RefundRequest); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, @@ -493,7 +493,7 @@ test(testCase, async (t: Test) => { try { await api.refundV1(parameters as any as RefundRequest); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, @@ -611,7 +611,7 @@ test(testCase, async (t: Test) => { try { await api.withdrawV1(parameters as any as WithdrawRequest); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, @@ -639,7 +639,7 @@ test(testCase, async (t: Test) => { try { await api.withdrawV1(parameters as any as WithdrawRequest); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, @@ -687,7 +687,7 @@ test(testCase, async (t: Test) => { try { await api.getStatusV1(parameters as any as GetStatusRequest); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, @@ -714,7 +714,7 @@ test(testCase, async (t: Test) => { try { await api.getStatusV1(parameters as any as GetStatusRequest); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, @@ -760,7 +760,7 @@ test(testCase, async (t: Test) => { try { await api.getSingleStatusV1(parameters as any as GetSingleStatusRequest); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, @@ -788,7 +788,7 @@ test(testCase, async (t: Test) => { // eslint-disable-next-line prettier/prettier await api.getSingleStatusV1(parameters as any as GetSingleStatusRequest); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, diff --git a/packages/cactus-test-plugin-htlc-eth-besu-erc20/src/test/typescript/integration/plugin-htlc-eth-besu-erc20/refund-endpoint-invalid-time.test.ts b/packages/cactus-test-plugin-htlc-eth-besu-erc20/src/test/typescript/integration/plugin-htlc-eth-besu-erc20/refund-endpoint-invalid-time.test.ts index dafd449acd..df1d2f3a90 100644 --- a/packages/cactus-test-plugin-htlc-eth-besu-erc20/src/test/typescript/integration/plugin-htlc-eth-besu-erc20/refund-endpoint-invalid-time.test.ts +++ b/packages/cactus-test-plugin-htlc-eth-besu-erc20/src/test/typescript/integration/plugin-htlc-eth-besu-erc20/refund-endpoint-invalid-time.test.ts @@ -282,7 +282,7 @@ describe(testCase, () => { const resRefund = await api.refundV1(refundRequest); expect(resRefund.status).toEqual(400); } catch (err) { - const e = err as AxiosError + const e = err as AxiosError; expect(e?.response?.status).toEqual(400); } diff --git a/packages/cactus-test-plugin-htlc-eth-besu-erc20/src/test/typescript/integration/plugin-htlc-eth-besu-erc20/refund-endpoint.test.ts b/packages/cactus-test-plugin-htlc-eth-besu-erc20/src/test/typescript/integration/plugin-htlc-eth-besu-erc20/refund-endpoint.test.ts index 56f0e3d002..f7d3f22850 100644 --- a/packages/cactus-test-plugin-htlc-eth-besu-erc20/src/test/typescript/integration/plugin-htlc-eth-besu-erc20/refund-endpoint.test.ts +++ b/packages/cactus-test-plugin-htlc-eth-besu-erc20/src/test/typescript/integration/plugin-htlc-eth-besu-erc20/refund-endpoint.test.ts @@ -586,7 +586,7 @@ test("Test invalid refund with invalid time", async (t: Test) => { const resRefund = await api.refundV1(refundRequest); t.equal(resRefund.status, 400, "response status is 400"); } catch (err) { - const e = err as AxiosError + const e = err as AxiosError; t.equal(e?.response?.status, 400, "response status is 400"); } diff --git a/packages/cactus-test-plugin-htlc-eth-besu-erc20/src/test/typescript/integration/plugin-htlc-eth-besu-erc20/withdraw-endpoint-invalid-id.test.ts b/packages/cactus-test-plugin-htlc-eth-besu-erc20/src/test/typescript/integration/plugin-htlc-eth-besu-erc20/withdraw-endpoint-invalid-id.test.ts index f921d1a6a0..c29e568aaa 100644 --- a/packages/cactus-test-plugin-htlc-eth-besu-erc20/src/test/typescript/integration/plugin-htlc-eth-besu-erc20/withdraw-endpoint-invalid-id.test.ts +++ b/packages/cactus-test-plugin-htlc-eth-besu-erc20/src/test/typescript/integration/plugin-htlc-eth-besu-erc20/withdraw-endpoint-invalid-id.test.ts @@ -250,7 +250,7 @@ describe(testCase, () => { const resWithdraw = await api.withdrawV1(withdrawRequest); expect(resWithdraw.status).toEqual(400); } catch (err) { - const e = err as AxiosError + const e = err as AxiosError; expect(e?.response?.status).toEqual(400); } diff --git a/packages/cactus-test-plugin-htlc-eth-besu/src/test/typescript/integration/plugin-htlc-eth-besu/get-single-status-endpoint-invalid.test.ts b/packages/cactus-test-plugin-htlc-eth-besu/src/test/typescript/integration/plugin-htlc-eth-besu/get-single-status-endpoint-invalid.test.ts index 2c22b82fb6..3ca01b1b08 100644 --- a/packages/cactus-test-plugin-htlc-eth-besu/src/test/typescript/integration/plugin-htlc-eth-besu/get-single-status-endpoint-invalid.test.ts +++ b/packages/cactus-test-plugin-htlc-eth-besu/src/test/typescript/integration/plugin-htlc-eth-besu/get-single-status-endpoint-invalid.test.ts @@ -206,7 +206,7 @@ describe(testCase, () => { }); expect(res.status).toEqual(500); } catch (err) { - const e = err as AxiosError + const e = err as AxiosError; expect(e?.response?.status).toEqual(500); } }); diff --git a/packages/cactus-test-plugin-htlc-eth-besu/src/test/typescript/integration/plugin-htlc-eth-besu/get-status-endpoint-invalid.test.ts b/packages/cactus-test-plugin-htlc-eth-besu/src/test/typescript/integration/plugin-htlc-eth-besu/get-status-endpoint-invalid.test.ts index a22f0ef843..6f29013777 100644 --- a/packages/cactus-test-plugin-htlc-eth-besu/src/test/typescript/integration/plugin-htlc-eth-besu/get-status-endpoint-invalid.test.ts +++ b/packages/cactus-test-plugin-htlc-eth-besu/src/test/typescript/integration/plugin-htlc-eth-besu/get-status-endpoint-invalid.test.ts @@ -208,7 +208,7 @@ describe(testCase, () => { }); expect(res.status).toEqual(500); } catch (err) { - const e = err as AxiosError + const e = err as AxiosError; expect(e?.response?.status).toEqual(500); } }); diff --git a/packages/cactus-test-plugin-htlc-eth-besu/src/test/typescript/integration/plugin-htlc-eth-besu/openapi/openapi-validation.test.ts b/packages/cactus-test-plugin-htlc-eth-besu/src/test/typescript/integration/plugin-htlc-eth-besu/openapi/openapi-validation.test.ts index 05c3c31e11..d205a66a2e 100644 --- a/packages/cactus-test-plugin-htlc-eth-besu/src/test/typescript/integration/plugin-htlc-eth-besu/openapi/openapi-validation.test.ts +++ b/packages/cactus-test-plugin-htlc-eth-besu/src/test/typescript/integration/plugin-htlc-eth-besu/openapi/openapi-validation.test.ts @@ -209,7 +209,7 @@ test(testCase, async (t: Test) => { try { await api.initializeV1(parameters as unknown as InitializeRequest); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, 400, @@ -240,14 +240,15 @@ test(testCase, async (t: Test) => { try { await api.initializeV1(parameters as unknown as InitializeRequest); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, t2.equal( e?.response?.status, 400, `Endpoint ${fInitialize} with fake=4: response.status === 400 OK`, - )); + ), + ); const fields = e?.response?.data.map((param: { path: string }) => param.path.replace("/body/", ""), ); @@ -322,14 +323,15 @@ test(testCase, async (t: Test) => { try { await api.newContractV1(parameters as unknown as NewContractObj); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, t2.equal( e?.response?.status, 400, `Endpoint ${fNew} without required contractAddress: response.status === 400 OK`, - )); + ), + ); const fields = e?.response?.data.map((param: { path: string }) => param.path.replace("/body/", ""), ); @@ -361,14 +363,15 @@ test(testCase, async (t: Test) => { try { await api.newContractV1(parameters as unknown as NewContractObj); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, t2.equal( e?.response?.status, 400, `Endpoint ${fNew} with fake=4: response.status === 400 OK`, - )) + ), + ); const fields = e?.response?.data.map((param: { path: string }) => param.path.replace("/body/", ""), ); @@ -427,14 +430,15 @@ test(testCase, async (t: Test) => { try { await api.refundV1(parameters as unknown as RefundReq); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, t2.equal( e?.response?.status, 400, `Endpoint ${fRefund} without required id: response.status === 400 OK`, - )) + ), + ); const fields = e?.response?.data.map((param: { path: string }) => param.path.replace("/body/", ""), ); @@ -455,14 +459,15 @@ test(testCase, async (t: Test) => { try { await api.refundV1(parameters as unknown as RefundReq); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, t2.equal( e?.response?.status, 400, `Endpoint ${fRefund} with fake=4: response.status === 400 OK`, - )) + ), + ); const fields = e?.response?.data.map((param: { path: string }) => param.path.replace("/body/", ""), ); @@ -538,14 +543,15 @@ test(testCase, async (t: Test) => { try { await api.withdrawV1(parameters as unknown as WithdrawReq); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, t2.equal( e?.response?.status, 400, `Endpoint ${fWithdraw} without required id: response.status === 400 OK`, - )) + ), + ); const fields = e?.response?.data.map((param: { path: string }) => param.path.replace("/body/", ""), ); @@ -569,14 +575,15 @@ test(testCase, async (t: Test) => { try { await api.withdrawV1(parameters as unknown as WithdrawReq); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, t2.equal( e?.response?.status, 400, `Endpoint ${fWithdraw} with fake=4: response.status === 400 OK`, - )) + ), + ); const fields = e?.response?.data.map((param: { path: string }) => param.path.replace("/body/", ""), ); @@ -661,14 +668,15 @@ test(testCase, async (t: Test) => { try { await api.getStatusV1(parameters as unknown as GetStatusRequest); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, t2.equal( e?.response?.status, 400, `Endpoint ${fStatus} without required ids: response.status === 400 OK`, - )) + ), + ); const fields = e?.response?.data.map((param: { path: string }) => param.path.replace("/body/", ""), ); @@ -690,14 +698,15 @@ test(testCase, async (t: Test) => { try { await api.getStatusV1(parameters as unknown as GetStatusRequest); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, t2.equal( e?.response?.status, 400, `Endpoint ${fStatus} with fake=4: response.status === 400 OK`, - )) + ), + ); const fields = e?.response?.data.map((param: { path: string }) => param.path.replace("/body/", ""), ); @@ -782,14 +791,15 @@ test(testCase, async (t: Test) => { parameters as unknown as GetSingleStatusRequest, ); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, t2.equal( e?.response?.status, 400, `Endpoint ${fSingleStatus} without required id: response.status === 400 OK`, - )) + ), + ); const fields = e?.response?.data.map((param: { path: string }) => param.path.replace("/body/", ""), ); @@ -813,14 +823,15 @@ test(testCase, async (t: Test) => { parameters as unknown as GetSingleStatusRequest, ); } catch (err) { - const e = err as AxiosError<{ path: string }[]> + const e = err as AxiosError<{ path: string }[]>; t2.equal( e?.response?.status, t2.equal( e?.response?.status, 400, `Endpoint ${fSingleStatus} with fake=4: response.status === 400 OK`, - )) + ), + ); const fields = e?.response?.data.map((param: { path: string }) => param.path.replace("/body/", ""), ); diff --git a/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/v21-sign-transaction-endpoint.test.ts b/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/v21-sign-transaction-endpoint.test.ts index c93b406184..9bb157e68e 100644 --- a/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/v21-sign-transaction-endpoint.test.ts +++ b/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/v21-sign-transaction-endpoint.test.ts @@ -191,7 +191,7 @@ test(testCase, async (t: Test) => { }; await api.signTransactionV1(notFoundRequest); } catch (err) { - const e = err as AxiosError + const e = err as AxiosError; t.equal(e.response?.status, 404, "HTTP response status are equal"); t.equal( e.response?.statusText, diff --git a/packages/cactus-test-tooling/src/main/typescript/fabric/fabric-test-ledger-v1.ts b/packages/cactus-test-tooling/src/main/typescript/fabric/fabric-test-ledger-v1.ts index dacf26df71..4381fc1924 100644 --- a/packages/cactus-test-tooling/src/main/typescript/fabric/fabric-test-ledger-v1.ts +++ b/packages/cactus-test-tooling/src/main/typescript/fabric/fabric-test-ledger-v1.ts @@ -483,17 +483,17 @@ export class FabricTestLedgerV1 implements ITestLedger { const connectionProfilePath = orgName === "org1" || orgName === "org2" ? path.join( - "fabric-samples/test-network", - "organizations/peerOrganizations", - orgName + ".example.com", - "connection-" + orgName + ".json", - ) + "fabric-samples/test-network", + "organizations/peerOrganizations", + orgName + ".example.com", + "connection-" + orgName + ".json", + ) : path.join( - "add-org-" + orgName, - "organizations/peerOrganizations", - orgName + ".example.com", - "connection-" + orgName + ".json", - ); + "add-org-" + orgName, + "organizations/peerOrganizations", + orgName + ".example.com", + "connection-" + orgName + ".json", + ); const peer0Name = `peer0.${orgName}.example.com`; const peer1Name = `peer1.${orgName}.example.com`; const cInfo = await this.getContainerInfo(); diff --git a/tools/generate-sbom.ts b/tools/generate-sbom.ts index d7b63f3b4a..c4e2bd6f54 100644 --- a/tools/generate-sbom.ts +++ b/tools/generate-sbom.ts @@ -259,6 +259,6 @@ export async function generateSBoM(req: { } } -export class ManifestParseError extends RuntimeError { } +export class ManifestParseError extends RuntimeError {} main(process.argv, process.env); diff --git a/weaver/core/drivers/fabric-driver/server/sample-satp.ts b/weaver/core/drivers/fabric-driver/server/sample-satp.ts index 6d8924c000..63da253788 100644 --- a/weaver/core/drivers/fabric-driver/server/sample-satp.ts +++ b/weaver/core/drivers/fabric-driver/server/sample-satp.ts @@ -1,357 +1,400 @@ -import satp_pb from '@hyperledger/cacti-weaver-protos-js/relay/satp_pb'; -import satp_grpc_pb from '@hyperledger/cacti-weaver-protos-js/relay/satp_grpc_pb'; -import driverPb from '@hyperledger/cacti-weaver-protos-js/driver/driver_pb'; -import logger from './logger'; -import { credentials } from '@grpc/grpc-js'; -import { SatpAssetManager, AssetManager, HashFunctions } from '@hyperledger/cacti-weaver-sdk-fabric' -import fs from 'fs'; -import { Gateway, Network } from 'fabric-network' +import satp_pb from "@hyperledger/cacti-weaver-protos-js/relay/satp_pb"; +import satp_grpc_pb from "@hyperledger/cacti-weaver-protos-js/relay/satp_grpc_pb"; +import driverPb from "@hyperledger/cacti-weaver-protos-js/driver/driver_pb"; +import logger from "./logger"; +import { credentials } from "@grpc/grpc-js"; +import { + SatpAssetManager, + AssetManager, + HashFunctions, +} from "@hyperledger/cacti-weaver-sdk-fabric"; +import fs from "fs"; +import { Gateway, Network } from "fabric-network"; import { getNetworkGateway } from "./fabric-code"; -import { getDriverKeyCert } from './walletSetup'; +import { getDriverKeyCert } from "./walletSetup"; async function performLockHelper( - performLockRequest: driverPb.PerformLockRequest, - networkName: string + performLockRequest: driverPb.PerformLockRequest, + networkName: string, ) { - - // TODO: remove the hardcoded values - let performLockRequest2 = {}; - performLockRequest2['target-network'] = 'network1'; - performLockRequest2['hashBase64'] = 'ivHErp1x4bJDKuRo6L5bApO/DdoyD/dG0mAZrzLZEIs='; - performLockRequest2['timeout-duration'] = parseInt('3600'); - performLockRequest2['locker'] = 'alice'; - performLockRequest2['recipient'] = 'bob'; - performLockRequest2['lockerWalletPath'] = '../wallet-network1/alice.id'; - performLockRequest2['recipientWalletPath'] = '../wallet-network1/bob.id'; - performLockRequest2['param'] = 'bond01:a05'; - performLockRequest2['channel'] = 'mychannel'; - performLockRequest2['chaincode-id'] = 'satpsimpleasset'; - - // Locker and recipient - const locker = performLockRequest2['locker']; - const recipient = performLockRequest2['recipient']; - const recipientWalletPath = performLockRequest2['recipientWalletPath']; - let hashFn = performLockRequest2['hash_fn']; - let hashBase64 = performLockRequest2['hashBase64']; - const targetNetwork = performLockRequest2['target-network']; - const channel = performLockRequest2['channel']; - const chaincodeId = performLockRequest2['chaincode-id']; - - // Hash - let hash: HashFunctions.Hash - if (hashFn == 'SHA512') { - hash = new HashFunctions.SHA512() + // TODO: remove the hardcoded values + const performLockRequest2 = {}; + performLockRequest2["target-network"] = "network1"; + performLockRequest2["hashBase64"] = + "ivHErp1x4bJDKuRo6L5bApO/DdoyD/dG0mAZrzLZEIs="; + performLockRequest2["timeout-duration"] = parseInt("3600"); + performLockRequest2["locker"] = "alice"; + performLockRequest2["recipient"] = "bob"; + performLockRequest2["lockerWalletPath"] = "../wallet-network1/alice.id"; + performLockRequest2["recipientWalletPath"] = "../wallet-network1/bob.id"; + performLockRequest2["param"] = "bond01:a05"; + performLockRequest2["channel"] = "mychannel"; + performLockRequest2["chaincode-id"] = "satpsimpleasset"; + + // Locker and recipient + const locker = performLockRequest2["locker"]; + const recipient = performLockRequest2["recipient"]; + const recipientWalletPath = performLockRequest2["recipientWalletPath"]; + const hashFn = performLockRequest2["hash_fn"]; + const hashBase64 = performLockRequest2["hashBase64"]; + const targetNetwork = performLockRequest2["target-network"]; + const channel = performLockRequest2["channel"]; + const chaincodeId = performLockRequest2["chaincode-id"]; + + // Hash + let hash: HashFunctions.Hash; + if (hashFn == "SHA512") { + hash = new HashFunctions.SHA512(); + } else { + hash = new HashFunctions.SHA256(); + } + + if (hashBase64) { + hash.setSerializedHashBase64(hashBase64); + } else { + logger.info(`No hash provided, using random preimage`); + } + + // Timeout + let timeout = 0; + const currTime = Math.floor(Date.now() / 1000); + if (performLockRequest2["timeout-epoch"]) { + timeout = performLockRequest2["timeout-epoch"]; + } else if (performLockRequest2["timeout-duration"]) { + timeout = currTime + performLockRequest2["timeout-duration"]; + } + + const gateway: Gateway = await getNetworkGateway(networkName); + const network: Network = await gateway.getNetwork(channel); + const contract = network.getContract(chaincodeId); + + const params = performLockRequest2["param"].split(":"); + const recipientCert = Buffer.from(recipientWalletPath).toString("base64"); + + let funcToCall, asset; + + try { + if (performLockRequest2["fungible"]) { + funcToCall = AssetManager.createFungibleHTLC; + asset = "Fungible Asset"; } else { - hash = new HashFunctions.SHA256() + funcToCall = AssetManager.createHTLC; + asset = "Asset"; } - if (hashBase64) { - hash.setSerializedHashBase64(hashBase64) + logger.info(`Asset Lock: Lock ${asset}:\n`); + + logger.info( + `Trying ${asset} Lock: ${params[0]}, ${params[1]} by ${locker} for ${recipient}`, + ); + const res = await funcToCall( + contract, + params[0], + params[1], + recipientCert, + hash, + timeout, + null, + ); + if (!res.result) { + throw new Error(); } - else { - logger.info(`No hash provided, using random preimage`) + logger.info( + `${asset} Locked with Contract Id: ${res.result}, preimage: ${res.hash.getPreimage()}, hashvalue: ${res.hash.getSerializedHashBase64()}`, + ); + logger.info("Asset has been locked successfully"); + } catch (error) { + logger.error(`Could not Lock ${asset} in ${targetNetwork}`); + } finally { + if (gateway) { + await gateway.disconnect(); + logger.info("Gateway disconnected."); } + } - // Timeout - let timeout = 0; - const currTime = Math.floor(Date.now() / 1000); - if (performLockRequest2['timeout-epoch']) { - timeout = performLockRequest2['timeout-epoch'] - } - else if (performLockRequest2['timeout-duration']) { - timeout = currTime + performLockRequest2['timeout-duration'] - } + const client = getRelayClientForAssetStatusResponse(); + const request = new satp_pb.SendAssetStatusRequest(); + request.setSessionId(performLockRequest.getSessionId()); + request.setStatus("Locked"); + client.sendAssetStatus(request, relayCallback); +} - let gateway: Gateway = await getNetworkGateway(networkName); - const network: Network = await gateway.getNetwork(channel); +async function createAssetHelper( + createAssetRequest: driverPb.CreateAssetRequest, + networkName: string, +) { + // TODO: remove the hardcoded values + const createAssetRequest2 = {}; + createAssetRequest2["target-network"] = "network1"; + createAssetRequest2["hashBase64"] = + "ivHErp1x4bJDKuRo6L5bApO/DdoyD/dG0mAZrzLZEIs="; + createAssetRequest2["timeout-duration"] = parseInt("3600"); + createAssetRequest2["owner"] = "admin"; + createAssetRequest2["type"] = "bond"; + createAssetRequest2["assetType"] = "bond01"; + createAssetRequest2["id"] = "a0demo"; + createAssetRequest2["issuer"] = "admin"; + createAssetRequest2["facevalue"] = "300"; + createAssetRequest2["maturitydate"] = "05 May 48 00:00 MST"; + createAssetRequest2["channel"] = "mychannel"; + createAssetRequest2["chaincode-id"] = "satpsimpleasset"; + + const owner = createAssetRequest2["owner"]; + const ccType = createAssetRequest2["type"]; + const assetType = createAssetRequest2["assetType"]; + const id = createAssetRequest2["id"]; + const issuer = createAssetRequest2["issuer"]; + const facevalue = createAssetRequest2["facevalue"]; + const maturitydate = createAssetRequest2["maturitydate"]; + const tokenassettype = createAssetRequest2["tokenassettype"]; + const numunits = createAssetRequest2["numunits"]; + const channel = createAssetRequest2["channel"]; + const chaincodeId = createAssetRequest2["chaincode-id"]; + + const gateway: Gateway = await getNetworkGateway(networkName); + const network: Network = await gateway.getNetwork(channel); + + try { const contract = network.getContract(chaincodeId); + const currentQuery = { + channel: channel, + contractName: chaincodeId, + ccFunc: "", + args: [], + }; + + const driverkeyCert = await getDriverKeyCert(); + const certificate = Buffer.from(driverkeyCert.cert).toString("base64"); + + if (ccType == "bond") { + currentQuery.ccFunc = "CreateAsset"; + currentQuery.args = [ + ...currentQuery.args, + assetType, + id, + certificate, + issuer, + facevalue, + maturitydate, + ]; + } else if (ccType == "token") { + currentQuery.ccFunc = "IssueTokenAssets"; + currentQuery.args = [ + ...currentQuery.args, + tokenassettype, + numunits, + certificate, + ]; + } else { + throw new Error(`Unrecognized asset category: ${ccType}`); + } + logger.info(currentQuery); + + logger.info( + `Trying creating the asset: type: ${ccType}, id: ${id}, by: ${owner}, facevalue: ${facevalue}, maturitydate: ${maturitydate}`, + ); + const read = await contract.submitTransaction( + currentQuery.ccFunc, + ...currentQuery.args, + ); + const state = Buffer.from(read).toString(); + if (state) { + logger.debug(`Response From Network: ${state}`); + logger.info("Asset has been created successfully"); + } else { + logger.debug("No Response from network"); + } + } catch (error) { + logger.error(`Failed to submit transaction: ${error}`); + throw new Error(error); + } finally { + if (gateway) { + await gateway.disconnect(); + logger.info("Gateway disconnected."); + } + } - const params = performLockRequest2['param'].split(':') - const recipientCert = Buffer.from(recipientWalletPath).toString('base64') + const client = getRelayClientForAssetStatusResponse(); + const request = new satp_pb.SendAssetStatusRequest(); + request.setSessionId(createAssetRequest.getSessionId()); + request.setStatus("Created"); + client.sendAssetStatus(request, relayCallback); +} - let funcToCall, asset +async function extinguishHelper(extinguishRequest: driverPb.ExtinguishRequest) { + // TODO: run the appropriate extinguish logic + const client = getRelayClientForAssetStatusResponse(); + const request = new satp_pb.SendAssetStatusRequest(); + request.setSessionId(extinguishRequest.getSessionId()); + request.setStatus("Extinguished"); + client.sendAssetStatus(request, relayCallback); +} +async function assignAssetHelper( + assignAssetRequest: driverPb.AssignAssetRequest, + networkName: string, +) { + // TODO: remove the hardcoded values + const assignAssetRequest2 = {}; + assignAssetRequest2["target-network"] = "network1"; + assignAssetRequest2["hashBase64"] = + "ivHErp1x4bJDKuRo6L5bApO/DdoyD/dG0mAZrzLZEIs="; + assignAssetRequest2["timeout-duration"] = parseInt("3600"); + assignAssetRequest2["locker"] = "admin"; + assignAssetRequest2["recipient"] = "bob"; + assignAssetRequest2["fungible"] = false; + assignAssetRequest2["contract-id"] = "abc01"; + assignAssetRequest2["hash_fn"] = ""; + assignAssetRequest2["secret"] = "secrettext"; + assignAssetRequest2["param"] = "bond01:a0demo"; + assignAssetRequest2["channel"] = "mychannel"; + assignAssetRequest2["chaincode-id"] = "satpsimpleasset"; + + const targetNetwork = assignAssetRequest2["target-network"]; + const locker = assignAssetRequest2["locker"]; + const recipient = assignAssetRequest2["recipient"]; + const fungible = assignAssetRequest2["fungible"]; + const hashFn = assignAssetRequest2["hash_fn"]; + const secret = assignAssetRequest2["secret"]; + const channel = assignAssetRequest2["channel"]; + const chaincodeId = assignAssetRequest2["chaincode-id"]; + + const gateway: Gateway = await getNetworkGateway(networkName); + const network: Network = await gateway.getNetwork(channel); + const contract = network.getContract(chaincodeId); + + // Hash + let hash: HashFunctions.Hash; + if (hashFn === "SHA512") { + hash = new HashFunctions.SHA512(); + } else { + hash = new HashFunctions.SHA256(); + } + hash.setPreimage(secret); + + let contractId: string = null; + if (assignAssetRequest2["contract-id"]) { + contractId = assignAssetRequest2["contract-id"]; + } + + const params = assignAssetRequest2["param"].split(":"); + + const funcToCall = SatpAssetManager.assignAsset; + let asset = assignAssetRequest2["param"]; + + if (assignAssetRequest2["fungible"]) { + // funcToCall = SatpAssetManager.claimFungibleAssetInHTLC + asset = "Fungible Asset"; + } + + if (fungible) { try { - if (performLockRequest2['fungible']) { - funcToCall = AssetManager.createFungibleHTLC - asset = 'Fungible Asset' - } else { - funcToCall = AssetManager.createHTLC - asset = 'Asset' - } - - logger.info(`Asset Lock: Lock ${asset}:\n`); - - logger.info(`Trying ${asset} Lock: ${params[0]}, ${params[1]} by ${locker} for ${recipient}`) - const res = await funcToCall(contract, - params[0], - params[1], - recipientCert, - hash, - timeout, - null) - if (!res.result) { - throw new Error() - } - logger.info(`${asset} Locked with Contract Id: ${res.result}, preimage: ${res.hash.getPreimage()}, hashvalue: ${res.hash.getSerializedHashBase64()}`) - logger.info('Asset has been locked successfully') + logger.info(`Trying assigning the asset with contract id ${contractId}`); + // TODO } catch (error) { - logger.error(`Could not Lock ${asset} in ${targetNetwork}`) + logger.error(`Could not assign ${asset} in ${targetNetwork}`); + throw new Error(`Could not assign ${asset} in ${targetNetwork}`); } finally { - if (gateway) { - await gateway.disconnect(); - logger.info('Gateway disconnected.'); - } + if (gateway) { + await gateway.disconnect(); + logger.info("Gateway disconnected."); + } } - - const client = getRelayClientForAssetStatusResponse(); - const request = new satp_pb.SendAssetStatusRequest(); - request.setSessionId(performLockRequest.getSessionId()); - request.setStatus("Locked"); - client.sendAssetStatus(request, relayCallback); -} - -async function createAssetHelper( - createAssetRequest: driverPb.CreateAssetRequest, - networkName: string -) { - - // TODO: remove the hardcoded values - let createAssetRequest2 = {}; - createAssetRequest2['target-network'] = 'network1'; - createAssetRequest2['hashBase64'] = 'ivHErp1x4bJDKuRo6L5bApO/DdoyD/dG0mAZrzLZEIs='; - createAssetRequest2['timeout-duration'] = parseInt('3600'); - createAssetRequest2['owner'] = 'admin'; - createAssetRequest2['type'] = 'bond'; - createAssetRequest2['assetType'] = 'bond01'; - createAssetRequest2['id'] = 'a0demo'; - createAssetRequest2['issuer'] = 'admin'; - createAssetRequest2['facevalue'] = '300'; - createAssetRequest2['maturitydate'] = '05 May 48 00:00 MST'; - createAssetRequest2['channel'] = 'mychannel'; - createAssetRequest2['chaincode-id'] = 'satpsimpleasset'; - - const owner = createAssetRequest2['owner']; - const ccType = createAssetRequest2['type']; - const assetType = createAssetRequest2['assetType']; - const id = createAssetRequest2['id']; - const issuer = createAssetRequest2['issuer']; - const facevalue = createAssetRequest2['facevalue']; - const maturitydate = createAssetRequest2['maturitydate']; - const tokenassettype = createAssetRequest2['tokenassettype']; - const numunits = createAssetRequest2['numunits']; - const channel = createAssetRequest2['channel']; - const chaincodeId = createAssetRequest2['chaincode-id']; - - let gateway: Gateway = await getNetworkGateway(networkName); - const network: Network = await gateway.getNetwork(channel); - + } else { try { - const contract = network.getContract(chaincodeId); - const currentQuery = { - channel: channel, - contractName: chaincodeId, - ccFunc: '', - args: [] - } - - const driverkeyCert = await getDriverKeyCert(); - const certificate = Buffer.from(driverkeyCert.cert).toString('base64') - - if (ccType == 'bond') { - currentQuery.ccFunc = 'CreateAsset' - currentQuery.args = [...currentQuery.args, assetType, id, certificate, issuer, facevalue, maturitydate] - } else if (ccType == 'token') { - currentQuery.ccFunc = 'IssueTokenAssets' - currentQuery.args = [...currentQuery.args, tokenassettype, numunits, certificate] - } else { - throw new Error(`Unrecognized asset category: ${ccType}`) - } - logger.info(currentQuery) - - logger.info(`Trying creating the asset: type: ${ccType}, id: ${id}, by: ${owner}, facevalue: ${facevalue}, maturitydate: ${maturitydate}`) - const read = await contract.submitTransaction(currentQuery.ccFunc, ...currentQuery.args) - const state = Buffer.from(read).toString() - if (state) { - logger.debug(`Response From Network: ${state}`) - logger.info('Asset has been created successfully') - } else { - logger.debug('No Response from network') - } + const driverkeyCert = await getDriverKeyCert(); + const certificate = Buffer.from(driverkeyCert.cert).toString("base64"); + + logger.info( + `Trying assign asset with params: ${params[0]}, ${params[1]} locked by ${locker} for ${recipient}`, + ); + const res = await funcToCall( + contract, + params[0], + params[1], + certificate, + hash, + ); + if (!res) { + throw new Error(); + } + logger.info(`${asset} assigned complete: ${res}`); + logger.info(`Asset ${asset} assign complete: ${res}`); } catch (error) { - logger.error(`Failed to submit transaction: ${error}`) - throw new Error(error) + logger.error( + `Could not assign non-fungible ${asset} in ${targetNetwork}: ${error}`, + ); + throw new Error( + `Could not assign non-fungible ${asset} in ${targetNetwork}: ${error}`, + ); } finally { - if (gateway) { - await gateway.disconnect(); - logger.info('Gateway disconnected.'); - } + if (gateway) { + await gateway.disconnect(); + logger.info("Gateway disconnected."); + } } const client = getRelayClientForAssetStatusResponse(); const request = new satp_pb.SendAssetStatusRequest(); - request.setSessionId(createAssetRequest.getSessionId()); - request.setStatus("Created"); - client.sendAssetStatus(request, relayCallback); -} - -async function extinguishHelper( - extinguishRequest: driverPb.ExtinguishRequest -) { - - // TODO: run the appropriate extinguish logic - const client = getRelayClientForAssetStatusResponse(); - const request = new satp_pb.SendAssetStatusRequest(); - request.setSessionId(extinguishRequest.getSessionId()); - request.setStatus("Extinguished"); + request.setSessionId(assignAssetRequest.getSessionId()); + request.setStatus("Finalized"); client.sendAssetStatus(request, relayCallback); -} - -async function assignAssetHelper( - assignAssetRequest: driverPb.AssignAssetRequest, - networkName: string -) { - - // TODO: remove the hardcoded values - let assignAssetRequest2 = {}; - assignAssetRequest2['target-network'] = 'network1'; - assignAssetRequest2['hashBase64'] = 'ivHErp1x4bJDKuRo6L5bApO/DdoyD/dG0mAZrzLZEIs='; - assignAssetRequest2['timeout-duration'] = parseInt('3600'); - assignAssetRequest2['locker'] = 'admin'; - assignAssetRequest2['recipient'] = 'bob'; - assignAssetRequest2['fungible'] = false; - assignAssetRequest2['contract-id'] = 'abc01'; - assignAssetRequest2['hash_fn'] = ''; - assignAssetRequest2['secret'] = 'secrettext'; - assignAssetRequest2['param'] = 'bond01:a0demo'; - assignAssetRequest2['channel'] = 'mychannel'; - assignAssetRequest2['chaincode-id'] = 'satpsimpleasset'; - - const targetNetwork = assignAssetRequest2['target-network']; - const locker = assignAssetRequest2['locker']; - const recipient = assignAssetRequest2['recipient']; - const fungible = assignAssetRequest2['fungible']; - const hashFn = assignAssetRequest2['hash_fn']; - const secret = assignAssetRequest2['secret']; - const channel = assignAssetRequest2['channel']; - const chaincodeId = assignAssetRequest2['chaincode-id']; - - let gateway: Gateway = await getNetworkGateway(networkName); - const network: Network = await gateway.getNetwork(channel); - const contract = network.getContract(chaincodeId); - - // Hash - let hash: HashFunctions.Hash - if (hashFn === 'SHA512') { - hash = new HashFunctions.SHA512() - } else { - hash = new HashFunctions.SHA256() - } - hash.setPreimage(secret) - - let contractId: string = null - if (assignAssetRequest2['contract-id']) { - contractId = assignAssetRequest2['contract-id'] - } - - const params = assignAssetRequest2['param'].split(':') - - let funcToCall = SatpAssetManager.assignAsset - let asset = assignAssetRequest2['param'] - - if (assignAssetRequest2['fungible']) { - // funcToCall = SatpAssetManager.claimFungibleAssetInHTLC - asset = 'Fungible Asset' - } - - if (fungible) { - try { - logger.info(`Trying assigning the asset with contract id ${contractId}`) - - // TODO - } catch (error) { - logger.error(`Could not assign ${asset} in ${targetNetwork}`) - throw new Error(`Could not assign ${asset} in ${targetNetwork}`) - } finally { - if (gateway) { - await gateway.disconnect(); - logger.info('Gateway disconnected.'); - } - } - } else { - try { - const driverkeyCert = await getDriverKeyCert(); - const certificate = Buffer.from(driverkeyCert.cert).toString('base64') - - logger.info(`Trying assign asset with params: ${params[0]}, ${params[1]} locked by ${locker} for ${recipient}`) - const res = await funcToCall(contract, - params[0], - params[1], - certificate, - hash) - if (!res) { - throw new Error() - } - logger.info(`${asset} assigned complete: ${res}`) - logger.info(`Asset ${asset} assign complete: ${res}`) - } catch (error) { - logger.error(`Could not assign non-fungible ${asset} in ${targetNetwork}: ${error}`) - throw new Error(`Could not assign non-fungible ${asset} in ${targetNetwork}: ${error}`) - } finally { - if (gateway) { - await gateway.disconnect(); - logger.info('Gateway disconnected.'); - } - } - - const client = getRelayClientForAssetStatusResponse(); - const request = new satp_pb.SendAssetStatusRequest(); - request.setSessionId(assignAssetRequest.getSessionId()); - request.setStatus("Finalized"); - client.sendAssetStatus(request, relayCallback); - } + } } function getRelayClientForAssetStatusResponse() { - let client: satp_grpc_pb.SATPClient; - if (process.env.RELAY_TLS === 'true') { - if (!process.env.RELAY_TLSCA_CERT_PATH || process.env.RELAY_TLSCA_CERT_PATH == "") { - client = new satp_grpc_pb.SATPClient( - process.env.RELAY_ENDPOINT, - credentials.createSsl() - ); - } else { - if (!(process.env.RELAY_TLSCA_CERT_PATH && fs.existsSync(process.env.RELAY_TLSCA_CERT_PATH))) { - throw new Error("Missing or invalid RELAY_TLSCA_CERT_PATH: " + process.env.RELAY_TLSCA_CERT_PATH); - } - const rootCert = fs.readFileSync(process.env.RELAY_TLSCA_CERT_PATH); - client = new satp_grpc_pb.SATPClient( - process.env.RELAY_ENDPOINT, - credentials.createSsl(rootCert) - ); - } + let client: satp_grpc_pb.SATPClient; + if (process.env.RELAY_TLS === "true") { + if ( + !process.env.RELAY_TLSCA_CERT_PATH || + process.env.RELAY_TLSCA_CERT_PATH == "" + ) { + client = new satp_grpc_pb.SATPClient( + process.env.RELAY_ENDPOINT, + credentials.createSsl(), + ); } else { - client = new satp_grpc_pb.SATPClient( - process.env.RELAY_ENDPOINT, - credentials.createInsecure() + if ( + !( + process.env.RELAY_TLSCA_CERT_PATH && + fs.existsSync(process.env.RELAY_TLSCA_CERT_PATH) + ) + ) { + throw new Error( + "Missing or invalid RELAY_TLSCA_CERT_PATH: " + + process.env.RELAY_TLSCA_CERT_PATH, ); + } + const rootCert = fs.readFileSync(process.env.RELAY_TLSCA_CERT_PATH); + client = new satp_grpc_pb.SATPClient( + process.env.RELAY_ENDPOINT, + credentials.createSsl(rootCert), + ); } - return client; + } else { + client = new satp_grpc_pb.SATPClient( + process.env.RELAY_ENDPOINT, + credentials.createInsecure(), + ); + } + return client; } // handle callback function relayCallback(err: any, response: any) { - if (response) { - logger.info(`Relay Callback Response: ${JSON.stringify(response.toObject())}`); - } else if (err) { - logger.error(`Relay Callback Error: ${err}`); - } + if (response) { + logger.info( + `Relay Callback Response: ${JSON.stringify(response.toObject())}`, + ); + } else if (err) { + logger.error(`Relay Callback Error: ${err}`); + } } export { - performLockHelper, - createAssetHelper, - extinguishHelper, - assignAssetHelper -} + performLockHelper, + createAssetHelper, + extinguishHelper, + assignAssetHelper, +}; diff --git a/weaver/core/drivers/fabric-driver/server/server.ts b/weaver/core/drivers/fabric-driver/server/server.ts index 31c0bfd2dc..1a5bdcce85 100644 --- a/weaver/core/drivers/fabric-driver/server/server.ts +++ b/weaver/core/drivers/fabric-driver/server/server.ts @@ -4,26 +4,45 @@ * SPDX-License-Identifier: Apache-2.0 */ -import fs from 'fs'; -import { Server, ServerCredentials, credentials } from '@grpc/grpc-js'; -import ack_pb from '@hyperledger/cacti-weaver-protos-js/common/ack_pb'; -import query_pb from '@hyperledger/cacti-weaver-protos-js/common/query_pb'; -import fabricViewPb from '@hyperledger/cacti-weaver-protos-js/fabric/view_data_pb'; -import eventsPb from '@hyperledger/cacti-weaver-protos-js/common/events_pb'; -import driver_pb_grpc from '@hyperledger/cacti-weaver-protos-js/driver/driver_grpc_pb'; -import datatransfer_grpc_pb from '@hyperledger/cacti-weaver-protos-js/relay/datatransfer_grpc_pb'; -import state_pb from '@hyperledger/cacti-weaver-protos-js/common/state_pb'; -import { invoke, packageFabricView } from './fabric-code'; -import 'dotenv/config'; -import { loadEventSubscriptionsFromStorage, monitorBlockForMissedEvents } from './listener' -import { walletSetup } from './walletSetup'; -import { subscribeEventHelper, unsubscribeEventHelper, signEventSubscriptionQuery, writeExternalStateHelper } from "./events" -import { performLockHelper, createAssetHelper, extinguishHelper, assignAssetHelper } from "./sample-satp" -import * as path from 'path'; -import { handlePromise, relayCallback, getRelayClientForQueryResponse, getRelayClientForEventSubscription, delay } from './utils'; -import { dbConnectionTest, eventSubscriptionTest } from "./tests" -import driverPb from '@hyperledger/cacti-weaver-protos-js/driver/driver_pb'; -import logger from './logger'; +import fs from "fs"; +import { Server, ServerCredentials, credentials } from "@grpc/grpc-js"; +import ack_pb from "@hyperledger/cacti-weaver-protos-js/common/ack_pb"; +import query_pb from "@hyperledger/cacti-weaver-protos-js/common/query_pb"; +import fabricViewPb from "@hyperledger/cacti-weaver-protos-js/fabric/view_data_pb"; +import eventsPb from "@hyperledger/cacti-weaver-protos-js/common/events_pb"; +import driver_pb_grpc from "@hyperledger/cacti-weaver-protos-js/driver/driver_grpc_pb"; +import datatransfer_grpc_pb from "@hyperledger/cacti-weaver-protos-js/relay/datatransfer_grpc_pb"; +import state_pb from "@hyperledger/cacti-weaver-protos-js/common/state_pb"; +import { invoke, packageFabricView } from "./fabric-code"; +import "dotenv/config"; +import { + loadEventSubscriptionsFromStorage, + monitorBlockForMissedEvents, +} from "./listener"; +import { walletSetup } from "./walletSetup"; +import { + subscribeEventHelper, + unsubscribeEventHelper, + signEventSubscriptionQuery, + writeExternalStateHelper, +} from "./events"; +import { + performLockHelper, + createAssetHelper, + extinguishHelper, + assignAssetHelper, +} from "./sample-satp"; +import * as path from "path"; +import { + handlePromise, + relayCallback, + getRelayClientForQueryResponse, + getRelayClientForEventSubscription, + delay, +} from "./utils"; +import { dbConnectionTest, eventSubscriptionTest } from "./tests"; +import driverPb from "@hyperledger/cacti-weaver-protos-js/driver/driver_pb"; +import logger from "./logger"; if (process.env.DEBUG === "true") { logger.level = "debug"; @@ -50,11 +69,10 @@ function mockCommunication(query: query_pb.Query) { meta.setProtocol(state_pb.Meta.Protocol.FABRIC); const view = new state_pb.View(); view.setMeta(meta); - const viewDataBinary = - fabricViewPb.FabricView.deserializeBinary( - //@ts-ignore - mockedB64Data, - ).serializeBinary(); + const viewDataBinary = fabricViewPb.FabricView.deserializeBinary( + //@ts-ignore + mockedB64Data, + ).serializeBinary(); logger.info(`viewData ${viewDataBinary}`); view.setData(viewDataBinary); const viewPayload = new state_pb.ViewPayload(); @@ -256,109 +274,162 @@ server.addService(driver_pb_grpc.DriverCommunicationService, { const viewPayload: state_pb.ViewPayload = call.request.getViewPayload(); const requestId: string = viewPayload.getRequestId(); - writeExternalStateHelper(call.request, process.env.NETWORK_NAME ? process.env.NETWORK_NAME : 'network1').then(() => { - const ack_response = new ack_pb.Ack(); - ack_response.setRequestId(requestId); - ack_response.setMessage('Successfully written to the ledger'); - ack_response.setStatus(ack_pb.Ack.STATUS.OK); - // gRPC response. - logger.info(`Responding to caller with Ack: ${JSON.stringify(ack_response.toObject())}`); - callback(null, ack_response); - }).catch((error) => { - const ack_err_response = new ack_pb.Ack(); - ack_err_response.setRequestId(requestId); - ack_err_response.setMessage(error.toString()); - ack_err_response.setStatus(ack_pb.Ack.STATUS.ERROR); - // gRPC response. - logger.info(`Responding to caller with error Ack: ${JSON.stringify(ack_err_response.toObject())}`); - callback(null, ack_err_response); - }); - }, - performLock: (call: { request: driverPb.PerformLockRequest }, callback: (_: any, object: ack_pb.Ack) => void) => { - const requestId: string = call.request.getSessionId(); - - performLockHelper(call.request, process.env.NETWORK_NAME ? process.env.NETWORK_NAME : 'network1').then(() => { - const ack_response = new ack_pb.Ack(); - ack_response.setRequestId(requestId); - ack_response.setMessage('Successfully locked the asset'); - ack_response.setStatus(ack_pb.Ack.STATUS.OK); - // gRPC response. - logger.info(`Responding to caller with Ack: ${JSON.stringify(ack_response.toObject())}`); - callback(null, ack_response); - }).catch((error) => { - const ack_err_response = new ack_pb.Ack(); - ack_err_response.setRequestId(requestId); - ack_err_response.setMessage(error.toString()); - ack_err_response.setStatus(ack_pb.Ack.STATUS.ERROR); - // gRPC response. - logger.info(`Responding to caller with error Ack: ${JSON.stringify(ack_err_response.toObject())}`); - callback(null, ack_err_response); - }); - }, - createAsset: (call: { request: driverPb.CreateAssetRequest }, callback: (_: any, object: ack_pb.Ack) => void) => { - const requestId: string = call.request.getSessionId(); + writeExternalStateHelper( + call.request, + process.env.NETWORK_NAME ? process.env.NETWORK_NAME : "network1", + ) + .then(() => { + const ack_response = new ack_pb.Ack(); + ack_response.setRequestId(requestId); + ack_response.setMessage("Successfully written to the ledger"); + ack_response.setStatus(ack_pb.Ack.STATUS.OK); + // gRPC response. + logger.info( + `Responding to caller with Ack: ${JSON.stringify(ack_response.toObject())}`, + ); + callback(null, ack_response); + }) + .catch((error) => { + const ack_err_response = new ack_pb.Ack(); + ack_err_response.setRequestId(requestId); + ack_err_response.setMessage(error.toString()); + ack_err_response.setStatus(ack_pb.Ack.STATUS.ERROR); + // gRPC response. + logger.info( + `Responding to caller with error Ack: ${JSON.stringify(ack_err_response.toObject())}`, + ); + callback(null, ack_err_response); + }); + }, + performLock: ( + call: { request: driverPb.PerformLockRequest }, + callback: (_: any, object: ack_pb.Ack) => void, + ) => { + const requestId: string = call.request.getSessionId(); - createAssetHelper(call.request, process.env.NETWORK_NAME ? process.env.NETWORK_NAME : 'network1').then(() => { - const ack_response = new ack_pb.Ack(); - ack_response.setRequestId(requestId); - ack_response.setMessage('Successfully created the asset'); - ack_response.setStatus(ack_pb.Ack.STATUS.OK); - // gRPC response. - logger.info(`Responding to caller with Ack: ${JSON.stringify(ack_response.toObject())}`); - callback(null, ack_response); - }).catch((error) => { - const ack_err_response = new ack_pb.Ack(); - ack_err_response.setRequestId(requestId); - ack_err_response.setMessage(error.toString()); - ack_err_response.setStatus(ack_pb.Ack.STATUS.ERROR); - // gRPC response. - logger.info(`Responding to caller with error Ack: ${JSON.stringify(ack_err_response.toObject())}`); - callback(null, ack_err_response); - }); - }, - extinguish: (call: { request: driverPb.ExtinguishRequest }, callback: (_: any, object: ack_pb.Ack) => void) => { - const requestId: string = call.request.getSessionId(); + performLockHelper( + call.request, + process.env.NETWORK_NAME ? process.env.NETWORK_NAME : "network1", + ) + .then(() => { + const ack_response = new ack_pb.Ack(); + ack_response.setRequestId(requestId); + ack_response.setMessage("Successfully locked the asset"); + ack_response.setStatus(ack_pb.Ack.STATUS.OK); + // gRPC response. + logger.info( + `Responding to caller with Ack: ${JSON.stringify(ack_response.toObject())}`, + ); + callback(null, ack_response); + }) + .catch((error) => { + const ack_err_response = new ack_pb.Ack(); + ack_err_response.setRequestId(requestId); + ack_err_response.setMessage(error.toString()); + ack_err_response.setStatus(ack_pb.Ack.STATUS.ERROR); + // gRPC response. + logger.info( + `Responding to caller with error Ack: ${JSON.stringify(ack_err_response.toObject())}`, + ); + callback(null, ack_err_response); + }); + }, + createAsset: ( + call: { request: driverPb.CreateAssetRequest }, + callback: (_: any, object: ack_pb.Ack) => void, + ) => { + const requestId: string = call.request.getSessionId(); - extinguishHelper(call.request).then(() => { - const ack_response = new ack_pb.Ack(); - ack_response.setRequestId(requestId); - ack_response.setMessage('Successfully extinguished the asset'); - ack_response.setStatus(ack_pb.Ack.STATUS.OK); - // gRPC response. - logger.info(`Responding to caller with Ack: ${JSON.stringify(ack_response.toObject())}`); - callback(null, ack_response); - }).catch((error) => { - const ack_err_response = new ack_pb.Ack(); - ack_err_response.setRequestId(requestId); - ack_err_response.setMessage(error.toString()); - ack_err_response.setStatus(ack_pb.Ack.STATUS.ERROR); - // gRPC response. - logger.info(`Responding to caller with error Ack: ${JSON.stringify(ack_err_response.toObject())}`); - callback(null, ack_err_response); - }); - }, - assignAsset: (call: { request: driverPb.AssignAssetRequest }, callback: (_: any, object: ack_pb.Ack) => void) => { - const requestId: string = call.request.getSessionId(); + createAssetHelper( + call.request, + process.env.NETWORK_NAME ? process.env.NETWORK_NAME : "network1", + ) + .then(() => { + const ack_response = new ack_pb.Ack(); + ack_response.setRequestId(requestId); + ack_response.setMessage("Successfully created the asset"); + ack_response.setStatus(ack_pb.Ack.STATUS.OK); + // gRPC response. + logger.info( + `Responding to caller with Ack: ${JSON.stringify(ack_response.toObject())}`, + ); + callback(null, ack_response); + }) + .catch((error) => { + const ack_err_response = new ack_pb.Ack(); + ack_err_response.setRequestId(requestId); + ack_err_response.setMessage(error.toString()); + ack_err_response.setStatus(ack_pb.Ack.STATUS.ERROR); + // gRPC response. + logger.info( + `Responding to caller with error Ack: ${JSON.stringify(ack_err_response.toObject())}`, + ); + callback(null, ack_err_response); + }); + }, + extinguish: ( + call: { request: driverPb.ExtinguishRequest }, + callback: (_: any, object: ack_pb.Ack) => void, + ) => { + const requestId: string = call.request.getSessionId(); - assignAssetHelper(call.request, process.env.NETWORK_NAME ? process.env.NETWORK_NAME : 'network1').then(() => { - const ack_response = new ack_pb.Ack(); - ack_response.setRequestId(requestId); - ack_response.setMessage('Successfully assigned the asset'); - ack_response.setStatus(ack_pb.Ack.STATUS.OK); - // gRPC response. - logger.info(`Responding to caller with Ack: ${JSON.stringify(ack_response.toObject())}`); - callback(null, ack_response); - }).catch((error) => { - const ack_err_response = new ack_pb.Ack(); - ack_err_response.setRequestId(requestId); - ack_err_response.setMessage(error.toString()); - ack_err_response.setStatus(ack_pb.Ack.STATUS.ERROR); - // gRPC response. - logger.info(`Responding to caller with error Ack: ${JSON.stringify(ack_err_response.toObject())}`); - callback(null, ack_err_response); - }); - }, + extinguishHelper(call.request) + .then(() => { + const ack_response = new ack_pb.Ack(); + ack_response.setRequestId(requestId); + ack_response.setMessage("Successfully extinguished the asset"); + ack_response.setStatus(ack_pb.Ack.STATUS.OK); + // gRPC response. + logger.info( + `Responding to caller with Ack: ${JSON.stringify(ack_response.toObject())}`, + ); + callback(null, ack_response); + }) + .catch((error) => { + const ack_err_response = new ack_pb.Ack(); + ack_err_response.setRequestId(requestId); + ack_err_response.setMessage(error.toString()); + ack_err_response.setStatus(ack_pb.Ack.STATUS.ERROR); + // gRPC response. + logger.info( + `Responding to caller with error Ack: ${JSON.stringify(ack_err_response.toObject())}`, + ); + callback(null, ack_err_response); + }); + }, + assignAsset: ( + call: { request: driverPb.AssignAssetRequest }, + callback: (_: any, object: ack_pb.Ack) => void, + ) => { + const requestId: string = call.request.getSessionId(); + assignAssetHelper( + call.request, + process.env.NETWORK_NAME ? process.env.NETWORK_NAME : "network1", + ) + .then(() => { + const ack_response = new ack_pb.Ack(); + ack_response.setRequestId(requestId); + ack_response.setMessage("Successfully assigned the asset"); + ack_response.setStatus(ack_pb.Ack.STATUS.OK); + // gRPC response. + logger.info( + `Responding to caller with Ack: ${JSON.stringify(ack_response.toObject())}`, + ); + callback(null, ack_response); + }) + .catch((error) => { + const ack_err_response = new ack_pb.Ack(); + ack_err_response.setRequestId(requestId); + ack_err_response.setMessage(error.toString()); + ack_err_response.setStatus(ack_pb.Ack.STATUS.ERROR); + // gRPC response. + logger.info( + `Responding to caller with error Ack: ${JSON.stringify(ack_err_response.toObject())}`, + ); + callback(null, ack_err_response); + }); + }, }); // Prepares required crypto material for communication with the fabric network diff --git a/weaver/sdks/fabric/interoperation-node-sdk/src/SatpAssetManager.ts b/weaver/sdks/fabric/interoperation-node-sdk/src/SatpAssetManager.ts index 4d5f5ec546..4e5bf5fd10 100644 --- a/weaver/sdks/fabric/interoperation-node-sdk/src/SatpAssetManager.ts +++ b/weaver/sdks/fabric/interoperation-node-sdk/src/SatpAssetManager.ts @@ -12,69 +12,67 @@ import log4js from "log4js"; import * as helpers from "./helpers"; import { Contract } from "fabric-network"; -import { Hash } from "./HashFunctions" -import { createAssetExchangeAgreementSerialized, createAssetClaimInfoSerialized} from "./AssetManager" +import { Hash } from "./HashFunctions"; +import { + createAssetExchangeAgreementSerialized, + createAssetClaimInfoSerialized, +} from "./AssetManager"; const logger = log4js.getLogger("InteroperableHelper"); - const assignAsset = async ( - contract: Contract, - assetType: string, - assetID: string, - lockerECert: string, - hash: Hash, - endorsingOrgs: Array = [] + contract: Contract, + assetType: string, + assetID: string, + lockerECert: string, + hash: Hash, + endorsingOrgs: Array = [], ): Promise => { + if (!contract) { + logger.error("Contract handle not supplied"); + return false; + } + if (!assetType) { + logger.error("Asset type not supplied"); + return false; + } + if (!assetID) { + logger.error("Asset ID not supplied"); + return false; + } + if (!lockerECert) { + logger.error("Locker ECert not supplied"); + return false; + } + if (!hash) { + logger.error("Instance of Hash interface not supplied"); + return false; + } + if (!hash.preimage) { + logger.error("Hash Preimage not supplied"); + return false; + } - if (!contract) - { - logger.error("Contract handle not supplied"); - return false; - } - if (!assetType) - { - logger.error("Asset type not supplied"); - return false; - } - if (!assetID) - { - logger.error("Asset ID not supplied"); - return false; - } - if (!lockerECert) - { - logger.error("Locker ECert not supplied"); - return false; - } - if (!hash) - { - logger.error("Instance of Hash interface not supplied") - return false - } - if (!hash.preimage) - { - logger.error("Hash Preimage not supplied"); - return false; - } - - const assetExchangeAgreementStr = createAssetExchangeAgreementSerialized(assetType, assetID, "", lockerECert); - const claimInfoStr = createAssetClaimInfoSerialized(hash); + const assetExchangeAgreementStr = createAssetExchangeAgreementSerialized( + assetType, + assetID, + "", + lockerECert, + ); + const claimInfoStr = createAssetClaimInfoSerialized(hash); - // Normal invoke function - const tx = contract.createTransaction("AssignAsset") - const ccArgs = [assetExchangeAgreementStr, claimInfoStr] - if (endorsingOrgs && endorsingOrgs.length > 0) { - tx.setEndorsingOrganizations(...endorsingOrgs) - } - const [result, submitError] = await helpers.handlePromise( - tx.submit(...ccArgs) - ); - if (submitError) { - throw new Error(`AssignAsset submitTransaction Error: ${submitError}`); - } - return result; + // Normal invoke function + const tx = contract.createTransaction("AssignAsset"); + const ccArgs = [assetExchangeAgreementStr, claimInfoStr]; + if (endorsingOrgs && endorsingOrgs.length > 0) { + tx.setEndorsingOrganizations(...endorsingOrgs); + } + const [result, submitError] = await helpers.handlePromise( + tx.submit(...ccArgs), + ); + if (submitError) { + throw new Error(`AssignAsset submitTransaction Error: ${submitError}`); + } + return result; }; -export { - assignAsset -}; +export { assignAsset };