Skip to content

Commit

Permalink
chore(js): resolved feedback to stay consistent between rn and nodejs
Browse files Browse the repository at this point in the history
Signed-off-by: Berend Sliedrecht <sliedrecht@berend.io>
  • Loading branch information
berendsliedrecht committed Dec 20, 2023
1 parent 37b2646 commit 531ac17
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,24 +104,22 @@ export class ReactNativeAriesAskar implements AriesAskar {
throw new AriesAskarError(this.getCurrentError())
}

private promisify = (method: (cb: Callback) => void): Promise<void> => {
private promisify(method: (cb: Callback) => void): Promise<void> {
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 = <Return>(
method: (cb: CallbackWithResponse<Return>) => void
): Promise<Return | null> => {
private promisifyWithResponse<Return>(method: (cb: CallbackWithResponse<Return>) => void): Promise<Return | null> {
return new Promise((resolve, reject) => {
const _cb: CallbackWithResponse<Return> = ({ errorCode, value }) => {
if (errorCode !== 0) {
Expand Down

0 comments on commit 531ac17

Please sign in to comment.