Skip to content

Commit

Permalink
error on callback fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Brord van Wierst committed Sep 6, 2023
1 parent 251686f commit 25d9aa4
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 10 deletions.
11 changes: 6 additions & 5 deletions bindings/nodejs/lib/bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const callClientMethodAsync = (
new Promise((resolve, reject) => {
callClientMethod(method, handler, (error: any, result: string) => {
if (error) {
reject(Error(error));
reject(error);
} else {
resolve(result);
}
Expand All @@ -53,7 +53,7 @@ const callSecretManagerMethodAsync = (
handler,
(error: any, result: string) => {
if (error) {
reject(Error(error));
reject(error);
} else {
resolve(result);
}
Expand All @@ -75,13 +75,14 @@ const listenWalletAsync = (
callback: (error: Error, event: Event) => void,
handler: WalletMethodHandler,
): Promise<void> => {
return new Promise((resolve, _) => {
return new Promise((resolve) => {
listenWallet(
eventTypes,
function (err: any, data: string) {
const parsed = JSON.parse(data);
callback(
Error(err),
// Send back raw error instead of parsing
err,
new Event(parsed.accountIndex, parsed.event),
);
},
Expand All @@ -98,7 +99,7 @@ const callWalletMethodAsync = (
new Promise((resolve, reject) => {
callWalletMethod(method, handler, (error: any, result: string) => {
if (error) {
reject(Error(error));
reject(error);
} else {
resolve(result);
}
Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function errorHandle(error: any): Error {
// neon or other bindings lib related error
throw error;
} else if (error instanceof Error) {
let err: Result = JSON.parse(error.message);
const err: Result = JSON.parse(error.message);
if (err.type == 'panic') {
return Error(err.payload.toString());
} else {
Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs/lib/wallet/wallet-method-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class WalletMethodHandler {
*/
getSecretManager(): SecretManager {
try {
let result = getSecretManagerFromWallet(this.methodHandler);
const result = getSecretManagerFromWallet(this.methodHandler);
return new SecretManager(result);
} catch (error: any) {
throw errorHandle(error);
Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub fn call_client_method(mut cx: FunctionContext) -> JsResult<JsUndefined> {

let args = [
if is_error {
cx.string(response.clone()).upcast::<JsValue>()
cx.error(response.clone())?.upcast::<JsValue>()
} else {
cx.undefined().upcast::<JsValue>()
},
Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs/src/secret_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub fn call_secret_manager_method(mut cx: FunctionContext) -> JsResult<JsUndefin

let args = vec![
if is_error {
cx.string(response.clone()).upcast::<JsValue>()
cx.error(response.clone())?.upcast::<JsValue>()
} else {
cx.undefined().upcast::<JsValue>()
},
Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub fn call_wallet_method(mut cx: FunctionContext) -> JsResult<JsUndefined> {

let args = [
if is_error {
cx.string(response.clone()).upcast::<JsValue>()
cx.error(response.clone())?.upcast::<JsValue>()
} else {
cx.undefined().upcast::<JsValue>()
},
Expand Down

0 comments on commit 25d9aa4

Please sign in to comment.