From 7b69dfd6ef2249f6e012dbf81789b539febf9fa3 Mon Sep 17 00:00:00 2001
From: mtyszczak <mateusz.tyszczak@gmail.com>
Date: Fri, 14 Mar 2025 16:07:37 +0100
Subject: [PATCH 1/2] Fix chain api error throwing

---
 ts/wasm/lib/detailed/chain_api.ts | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/ts/wasm/lib/detailed/chain_api.ts b/ts/wasm/lib/detailed/chain_api.ts
index 7f0a44507..3ba31799f 100644
--- a/ts/wasm/lib/detailed/chain_api.ts
+++ b/ts/wasm/lib/detailed/chain_api.ts
@@ -2,7 +2,7 @@ import type { IHiveChainInterface, IManabarData, ITransaction, IOnlineTransactio
 import type { MainModule, MapStringUInt16, wax_authority, wax_authorities } from "../build_wasm/wax.common";
 import { ApiAuthority, ApiWitness, type ApiAccount, type ApiManabar, type ApiTransaction, type RcAccount } from "./api";
 
-import { WaxError } from "./errors.js";
+import { WaxError, WaxChainApiError } from "./errors.js";
 import { safeWasmCall } from './util/wasm_errors.js';
 import { ONE_HUNDRED_PERCENT, WaxBaseApi } from "./base_api.js";
 import { HiveApiTypes, HiveRestApiTypes } from "./chain_api_data.js";
@@ -76,7 +76,7 @@ export class HiveChainApi extends WaxBaseApi implements IHiveChainInterface {
       if (typeof data.response === "object" && "result" in data.response)
         data.response = data.response.result;
       else
-        throw new WaxError(`Invalid response from API: ${JSON.stringify(data.response)}`);
+        throw new WaxChainApiError(`Invalid response from API: ${JSON.stringify(data.response)}`, data.response);
 
       return data;
     });
-- 
GitLab


From d41dec39ebe5fd2bc7852e7a50d7ad3c26279a6c Mon Sep 17 00:00:00 2001
From: mtyszczak <mateusz.tyszczak@gmail.com>
Date: Fri, 14 Mar 2025 17:16:17 +0100
Subject: [PATCH 2/2] Fix setting proper error messages in safe wasm call
 wrapper

---
 ts/wasm/lib/detailed/util/wasm_errors.ts | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/ts/wasm/lib/detailed/util/wasm_errors.ts b/ts/wasm/lib/detailed/util/wasm_errors.ts
index 43ae0421c..dad8ceb1c 100644
--- a/ts/wasm/lib/detailed/util/wasm_errors.ts
+++ b/ts/wasm/lib/detailed/util/wasm_errors.ts
@@ -54,7 +54,9 @@ export const safeWasmCall = <T extends () => any>(fn: T, customExceptionHandler?
     handleWaxStdException(e, customExceptionHandler);
     //console.log("Non-typed Error during Wasm call...", e);
 
-    const error = new WaxError(`Non-typed Error during Wasm call: ${e}`);
+    const errorMsg = e && typeof e === "object" && "message" in e ? e.message : String(e);
+
+    const error = new WaxError(`Non-typed Error during Wasm call: ${errorMsg}`);
 
     if (typeof e === "object" && e && "stack" in e)
       throw Object.assign(error, { stack: e.stack });
@@ -70,7 +72,9 @@ export const safeAsyncWasmCall = async <T extends () => any>(fn: T, customExcept
     handleWaxStdException(e, customExceptionHandler);
     //console.log("Non-typed Error during Wasm call...", e); 
 
-    const error = new WaxError(`Non-typed Error during Wasm call: ${e}`);
+    const errorMsg = e && typeof e === "object" && "message" in e ? e.message : String(e);
+
+    const error = new WaxError(`Non-typed Error during Wasm call: ${errorMsg}`);
 
     if (typeof e === "object" && e && "stack" in e)
       throw Object.assign(error, { stack: e.stack });
-- 
GitLab