From 531ac1767a330bdd03ddcb4c085412432bb0aa04 Mon Sep 17 00:00:00 2001 From: Berend Sliedrecht Date: Wed, 20 Dec 2023 11:05:19 +0100 Subject: [PATCH] chore(js): resolved feedback to stay consistent between rn and nodejs Signed-off-by: Berend Sliedrecht --- Cargo.lock | 6 +++--- .../aries-askar-nodejs/src/NodeJSAriesAskar.ts | 6 +++++- .../src/ReactNativeAriesAskar.ts | 16 +++++++--------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8556d8eb..6090ecc1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1183,11 +1183,11 @@ dependencies = [ [[package]] name = "home" -version = "0.5.9" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb" dependencies = [ - "windows-sys 0.52.0", + "windows-sys 0.48.0", ] [[package]] diff --git a/wrappers/javascript/aries-askar-nodejs/src/NodeJSAriesAskar.ts b/wrappers/javascript/aries-askar-nodejs/src/NodeJSAriesAskar.ts index 961e6888..61997721 100644 --- a/wrappers/javascript/aries-askar-nodejs/src/NodeJSAriesAskar.ts +++ b/wrappers/javascript/aries-askar-nodejs/src/NodeJSAriesAskar.ts @@ -200,7 +200,11 @@ export class NodeJSAriesAskar implements AriesAskar { if (errorCode === 0) return const error = this.getCurrentError() - if (error.code === 0) return + if (error.code !== errorCode) { + throw AriesAskarError.customError({ + message: `Error code mismatch. Function received: '${errorCode}', but after fetch it was '${error.code}'`, + }) + } throw new AriesAskarError(error) } diff --git a/wrappers/javascript/aries-askar-react-native/src/ReactNativeAriesAskar.ts b/wrappers/javascript/aries-askar-react-native/src/ReactNativeAriesAskar.ts index ddc691db..cc13d7fb 100644 --- a/wrappers/javascript/aries-askar-react-native/src/ReactNativeAriesAskar.ts +++ b/wrappers/javascript/aries-askar-react-native/src/ReactNativeAriesAskar.ts @@ -104,24 +104,22 @@ export class ReactNativeAriesAskar implements AriesAskar { throw new AriesAskarError(this.getCurrentError()) } - private promisify = (method: (cb: Callback) => void): Promise => { + private promisify(method: (cb: Callback) => void): Promise { return new Promise((resolve, reject) => { const _cb: Callback = ({ errorCode }) => { - if (errorCode !== 0) { - const error = this.getCurrentError() - reject(new AriesAskarError(error)) + try { + this.handleError({ errorCode }) + resolve() + } catch (e) { + reject(e) } - - resolve() } method(_cb) }) } - private promisifyWithResponse = ( - method: (cb: CallbackWithResponse) => void - ): Promise => { + private promisifyWithResponse(method: (cb: CallbackWithResponse) => void): Promise { return new Promise((resolve, reject) => { const _cb: CallbackWithResponse = ({ errorCode, value }) => { if (errorCode !== 0) {