Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flag catch rebase #39

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
e6d232c
flag-stap-hermes
rwat17 Apr 30, 2024
b91e670
cactus-common
rwat17 May 7, 2024
35e92a8
cmd-socketio-server
rwat17 May 9, 2024
e7395bc
cmd-api-server
rwat17 May 9, 2024
9a9adf8
api-client
rwat17 May 10, 2024
3fdaf17
cactus-core
rwat17 May 10, 2024
71a7e5a
bungee-hermes
rwat17 May 10, 2024
a78d35b
plugin-consortium
rwat17 May 10, 2024
b7c2428
plugin-htlc-eth-besu
rwat17 May 13, 2024
6d16c2b
plugin-htlc-eth-besu-erc20
rwat17 May 13, 2024
65277f9
plugin-keychain-aws-sm
rwat17 May 13, 2024
dd07725
plugin-keychain-azure-kv
rwat17 May 13, 2024
5c893b4
plugin-keychain-google-sm
rwat17 May 14, 2024
7d50dbe
plugin-keychain-memory
rwat17 May 14, 2024
1de5380
plugin-keychain-memory-wasm
rwat17 May 14, 2024
99cc67d
plugin-keychain-vault
rwat17 May 15, 2024
8b3a8fa
plugin-ledger-connector-besu
rwat17 May 15, 2024
9570262
plugin-ledger-connector-cdl
rwat17 May 15, 2024
bb06c1a
plugin-ledger-connector-corda
rwat17 May 15, 2024
59bf800
plugin-ledger-connector-corda
rwat17 May 15, 2024
24c5f4f
plugin-ledger-connector-ethereum
rwat17 May 15, 2024
a41ce72
plugin-ledger-connector-fabric
rwat17 May 15, 2024
8a98593
plugin-ledger-connector-iroha2
rwat17 May 16, 2024
adfef71
cmd-api-server
rwat17 May 16, 2024
ced399d
plugin-ledger-connector-quorum
rwat17 May 16, 2024
1c8d9f8
plugin-ledger-connector-xdai
rwat17 May 16, 2024
f0c057a
plugin-consortium-manual
rwat17 May 16, 2024
db23bc3
plugin-htlc-eth-besu
rwat17 May 16, 2024
f5af9ab
plugin-htlc-eth-besu-erc20
rwat17 May 16, 2024
90f3025
plugin-ledger-connector-besu
rwat17 May 17, 2024
7f127d9
cactus-test-tooling
rwat17 May 17, 2024
7b39c4b
tools
rwat17 May 17, 2024
beb6e70
extensions
rwat17 May 17, 2024
0cd4f3c
plugin-ledger-connector-fabric
rwat17 May 17, 2024
2540916
plugin-object-store-ipfs
rwat17 May 17, 2024
2647b85
example-carbon-accounting-backend
rwat17 May 17, 2024
15d876b
example-discounted-asset-trade
rwat17 May 17, 2024
af39d46
prettier and endpoint catch handling fix
rwat17 May 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from "jose";
import { StatusCodes } from "http-status-codes";
import jsonStableStringify from "json-stable-stringify";

import { AxiosError } from "axios";
import {
AuthorizationProtocol,
ConfigService,
Expand Down Expand Up @@ -46,6 +46,17 @@ const log = LoggerProvider.getOrCreate({
level: logLevel,
});

interface ResponseError extends AxiosError {
response: {
data: any;
status: number;
statusText: string;
headers: any;
config: any;
request?: any;
};
}

test("BEFORE " + testCase, async (t: Test) => {
const pruning = pruneDockerAllIfGithubAction({ logLevel });
await t.doesNotReject(pruning, "Pruning didn't throw OK");
Expand Down Expand Up @@ -181,16 +192,18 @@ test.skip(testCase, async (t: Test) => {
try {
await apiClientBad.enrollAdminV1({ orgName: "does-not-matter" });
t.fail("enroll admin response status === 403 FAIL");
} catch (out) {
t.ok(out, "error thrown for forbidden endpoint truthy OK");
t.ok(out.response, "enroll admin response truthy OK");
} catch (err) {
const e = err as ResponseError;

t.ok(e, "error thrown for forbidden endpoint truthy OK");
t.ok(e.response, "enroll admin response truthy OK");
t.equal(
out.response.status,
e?.response?.status,
StatusCodes.FORBIDDEN,
"enroll admin response status === 403 OK",
);
t.notok(out.response.data.data, "out.response.data.data falsy OK");
t.notok(out.response.data.success, "out.response.data.success falsy OK");
t.notok(e?.response?.data?.data, "out.response.data.data falsy OK");
t.notok(e?.response?.data?.success, "out.response.data.success falsy OK");
}

t.end();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,12 @@ async function menuLoop(agent: AnoncredAgent) {
break;
}
} catch (error) {
if (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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import escapeHtml from "escape-html";
import { getLogger } from "log4js";
import { ConfigUtil } from "@hyperledger/cactus-cmd-socketio-server";
import { connectToClientAgent } from "./transaction-indy";
import { safeStringifyException } from "@hyperledger/cactus-common";

const config: any = ConfigUtil.getConfig();
const moduleName = "indy-endpoints";
Expand Down Expand Up @@ -38,7 +39,7 @@ router.post(
});
} catch (err) {
res.status(500).send({
error: escapeHtml(err),
error: escapeHtml(safeStringifyException(err)),
});
next(err);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ export class PluginHTLCCoordinatorBesu
try {
const res = await pluginHtlc.withdraw(withdrawRequest);
return res;
} catch (ex: unknown) {
} catch (ex) {
const cause = ex instanceof Error ? ex : fastSafeStringify(ex);
throw new WithdrawCounterpartyTxReverted(`EVM tx reverted:`, cause);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from "@hyperledger/cactus-common";
import {
PluginRegistry,
handleRestEndpointException,
registerWebServiceEndpoint,
} from "@hyperledger/cactus-core";
import { CounterpartyHTLCRequest } from "../generated/openapi/typescript-axios";
Expand Down Expand Up @@ -108,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?.stack || ex?.message,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uzyj handleRestEndpointException jak w innych endpoint

});
const errorMsg = "Internal Server Error";
handleRestEndpointException({ errorMsg, log: this.log, error: ex, res });
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 });
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class WithdrawCounterpartyEndpoint implements IWebServiceEndpoint {
}) as unknown as PluginHTLCCoordinatorBesu;
const resBody = await connector.withdrawCounterparty(request);
res.json(resBody);
} catch (ex: unknown) {
} catch (ex) {
if (ex instanceof WithdrawCounterpartyTxReverted) {
this.log.debug("%o %o", reqTag, ex);
res.status(400).json(ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,12 @@ export class PluginObjectStoreIpfs implements IPluginObjectStore {
this.log.debug(`StatResult for ${req.key}: %o`, statResult);
return { key: req.key, checkedAt, isPresent: true };
} catch (ex) {
if (ex?.stack?.includes(K_IPFS_JS_HTTP_ERROR_FILE_DOES_NOT_EXIST)) {
if (ex instanceof Error && ex?.stack?.includes(K_IPFS_JS_HTTP_ERROR_FILE_DOES_NOT_EXIST)) {
const msg = `Stat ${req.key} failed with error message containing phrase "${K_IPFS_JS_HTTP_ERROR_FILE_DOES_NOT_EXIST}" Returning isPresent=false ...`;
this.log.debug(msg);
return { key: req.key, checkedAt, isPresent: false };
} else {
throw new RuntimeError(`Checking presence of ${req.key} crashed:`, ex);
throw new RuntimeError(`Checking presence of ${req.key} crashed: ${ex}`,);
}
}
}
Expand All @@ -204,7 +204,7 @@ export class PluginObjectStoreIpfs implements IPluginObjectStore {
parents: true,
});
} catch (ex) {
throw new RuntimeError(`Can't set object ${keyPath}. Write failed:`, ex);
throw new RuntimeError(`Can't set object ${keyPath}. Write failed: ${ex}`);
}
return {
key: req.key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -93,8 +96,8 @@ export class GetObjectEndpointV1 implements IWebServiceEndpoint {
res.json(resBody);
} catch (ex) {
this.log.error(`${tag} Failed to serve request:`, ex);
res.status(500);
res.json({ error: ex.stack });
const errorMsg = "Internal Server Error";
handleRestEndpointException({ errorMsg, log: this.log, error: ex, res });
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -93,8 +96,8 @@ export class HasObjectEndpointV1 implements IWebServiceEndpoint {
res.json(resBody);
} catch (ex) {
this.log.error(`${tag} Failed to serve request:`, ex);
res.status(500);
res.json({ error: ex.stack });
const errorMsg = "Internal Server Error";
handleRestEndpointException({ errorMsg, log: this.log, error: ex, res });
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -93,8 +96,8 @@ export class SetObjectEndpointV1 implements IWebServiceEndpoint {
res.json(resBody);
} catch (ex) {
this.log.error(`${tag} Failed to serve request:`, ex);
res.status(500);
res.json({ error: ex.stack });
const errorMsg = "Internal Server Error";
handleRestEndpointException({ errorMsg, log: this.log, error: ex, res });
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ export interface IDefaultConsortiumProviderOptions {
}

export class DefaultConsortiumProvider
implements IAsyncProvider<ConsortiumDatabase>
{
implements IAsyncProvider<ConsortiumDatabase> {
public static readonly CLASS_NAME = "DefaultConsortiumProvider";

private readonly log: Logger;
Expand Down Expand Up @@ -64,9 +63,15 @@ export class DefaultConsortiumProvider
const res = await this.options.apiClient.getConsortiumJwsV1();
return this.parseConsortiumJws(res.data);
} catch (ex) {
const innerException = (ex.toJSON && ex.toJSON()) || ex;
this.log.error(`Request for Consortium JWS failed: `, innerException);
throw ex;
if (ex instanceof Date && ex !== null) {
const innerException = (ex.toJSON && ex.toJSON())
this.log.error(`Request for Consortium JWS failed: `, innerException);
throw ex;
} else {
this.log.error(`Request for Consortium JWS failed: `, ex);
throw ex;
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +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) {
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");
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();
});
Expand All @@ -57,17 +66,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) {
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("status code 404"),
"Has Status Code in msg OK",
);
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("status code 404"),
"Has Status Code in msg OK",
);
}
} else {
t2.ok(ex, "Thrown error truthy OK");
}
}
t2.end();
});
Expand Down
Loading
Loading