diff --git a/core/src.ts/drivers/common.ts b/core/src.ts/drivers/common.ts index 3585510..a349242 100644 --- a/core/src.ts/drivers/common.ts +++ b/core/src.ts/drivers/common.ts @@ -41,6 +41,7 @@ import { HaloResponseObject } from "../types.js"; import {Buffer} from 'buffer/index.js'; +import {arr2hex, isWebDebugEnabled} from "../halo/util.js"; async function execHaloCmd(command: HaloCommandObject, options: ExecHaloCmdOptions): Promise { command = Object.assign({}, command); @@ -103,12 +104,19 @@ async function execHaloCmd(command: HaloCommandObject, options: ExecHaloCmdOptio } function checkErrors(res: Buffer) { + const webDebug = isWebDebugEnabled(); + if (res.length === 2 && res[0] === 0xE1) { + if (webDebug) { + console.log('[libhalo] execCredential() command fail:', arr2hex(res)); + } + if (Object.prototype.hasOwnProperty.call(ERROR_CODES, res[1])) { const err = ERROR_CODES[res[1]]; - throw new HaloTagError(err[0], "Tag responded with error: [" + err[0] + "] " + err[1]); + throw new HaloTagError(err[0], err[1]); } else { - throw new HaloLogicError("Tag responded with unknown error: " + res.toString('hex')); + const errCode = arr2hex([res[1]]); + throw new HaloTagError("ERROR_CODE_" + errCode, "Command returned an unknown error: " + arr2hex(res)); } } } diff --git a/core/src.ts/drivers/credential.ts b/core/src.ts/drivers/credential.ts index 3cb5d79..b98fa32 100644 --- a/core/src.ts/drivers/credential.ts +++ b/core/src.ts/drivers/credential.ts @@ -4,11 +4,11 @@ * License: MIT */ -import {HaloTagError, NFCOperationError, NFCMethodNotSupported} from "../halo/exceptions.js"; -import {ERROR_CODES} from "../halo/errors.js"; +import {NFCOperationError, NFCMethodNotSupported} from "../halo/exceptions.js"; import {arr2hex, isWebDebugEnabled} from "../halo/util.js"; import {ExecOptions, ExecReturnStruct} from "../types.js"; import {Buffer} from 'buffer/index.js'; +import {checkErrors} from "./common.js"; async function execCredential(request: Buffer, options: ExecOptions): Promise { const webDebug = isWebDebugEnabled(); @@ -87,19 +87,7 @@ async function execCredential(request: Buffer, options: ExecOptions): Promise