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 <[email protected]>
  • Loading branch information
Berend Sliedrecht committed Dec 20, 2023
1 parent 37b2646 commit a319774
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,10 @@ 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 a319774

Please sign in to comment.