Skip to content

Commit

Permalink
Improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegec committed Jan 17, 2025
1 parent 4f63b84 commit 5dd7295
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions ohos/src/main/ets/components/plugin/FlutterNfcKitPlugin.ets
Original file line number Diff line number Diff line change
Expand Up @@ -141,22 +141,31 @@ export default class FlutterNfcKitPlugin implements FlutterPlugin, MethodCallHan
} else if (call.method == "transceive") {
let tx: string = call.argument("data");
hilog.info(0x0000, "FlutterNfcKitPlugin", "transceive: tx=%{public}s", JSON.stringify(tx));
this.tag!.connect();
this.tag!.transmit(fromHexString(tx)).then((rx) => {
hilog.info(0x0000, "FlutterNfcKitPlugin", "transceive: rx=%{public}s", JSON.stringify(rx));
result.success(toHexString(rx));
}).catch((err: BusinessError) => {
hilog.info(0x0000, "FlutterNfcKitPlugin", "Failed to transceive: err=%{public}s", JSON.stringify(err));
result.error("500", "Transceive failed", err);
});
if (this.tag !== null) {
this.tag!.connect();
this.tag!.transmit(fromHexString(tx)).then((rx) => {
hilog.info(0x0000, "FlutterNfcKitPlugin", "transceive: rx=%{public}s", JSON.stringify(rx));
result.success(toHexString(rx));
}).catch((err: BusinessError) => {
hilog.info(0x0000, "FlutterNfcKitPlugin", "Failed to transceive: err=%{public}s", JSON.stringify(err));
result.error("500", "Transceive failed", err);
});
} else {
result.error("406", "No tag polled", null);
}
} else if (call.method == "finish") {
// turn off reader mode
tag.off("readerMode", elementName, (err: BusinessError, tagInfo: tag.TagInfo) => {});
this.tag = null;
result.success("");
} else if (call.method == "setIosAlertMessage") {
// do nothing, just for compatibility
result.success("");
} else if (call.method == "readNDEF") {
// TODO
result.success("[]");
} else {
hilog.info(0x0000, "FlutterNfcKitPlugin", "Not implemented method: %{public}s", call.method);
result.notImplemented();
}
} catch (e) {
Expand Down

0 comments on commit 5dd7295

Please sign in to comment.