aboutsummaryrefslogtreecommitdiff
path: root/src/walletCoreApiHandler.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2020-07-29 22:53:17 +0530
committerFlorian Dold <florian.dold@gmail.com>2020-07-29 22:53:17 +0530
commitdfe5e95bc8537e13c482fff42cfefeb090eb2e09 (patch)
tree028d307a9536fce64a4868aeddc8c11e1ed84e0c /src/walletCoreApiHandler.ts
parent9a4cbcd9549fee9865a537ed5236e2a2ebe52cf1 (diff)
downloadwallet-core-dfe5e95bc8537e13c482fff42cfefeb090eb2e09.tar.xz
fix Android response, stronger typingv0.7.1-dev.12
Diffstat (limited to 'src/walletCoreApiHandler.ts')
-rw-r--r--src/walletCoreApiHandler.ts30
1 files changed, 27 insertions, 3 deletions
diff --git a/src/walletCoreApiHandler.ts b/src/walletCoreApiHandler.ts
index 3c1bf007b..02b916af7 100644
--- a/src/walletCoreApiHandler.ts
+++ b/src/walletCoreApiHandler.ts
@@ -249,6 +249,28 @@ async function dispatchRequestInternal(
);
}
+export type CoreApiResponse =
+ | CoreApiResponseSuccess
+ | CoreApiResponseError;
+
+export interface CoreApiResponseSuccess {
+ // To distinguish the message from notifications
+ type: "response";
+ isError: false,
+ operation: string,
+ id: string;
+ result: unknown;
+}
+
+export interface CoreApiResponseError {
+ // To distinguish the message from notifications
+ type: "response";
+ isError: true,
+ operation: string,
+ id: string;
+ error: unknown;
+}
+
/**
* Handle a request to the wallet-core API.
*/
@@ -257,16 +279,16 @@ export async function handleCoreApiRequest(
operation: string,
id: string,
payload: unknown,
-): Promise<unknown> {
+): Promise<CoreApiResponse> {
try {
const result = await dispatchRequestInternal(w, operation, payload);
- const respMsg = {
+ return {
isError: false,
operation,
id,
result,
+ type: "response",
};
- return respMsg;
} catch (e) {
if (
e instanceof OperationFailedError ||
@@ -277,6 +299,7 @@ export async function handleCoreApiRequest(
operation,
id,
error: e.operationError,
+ type: "response",
};
} else {
return {
@@ -288,6 +311,7 @@ export async function handleCoreApiRequest(
`unexpected exception: ${e}`,
{},
),
+ type: "response",
};
}
}