From aea0cd19b9d93e8d799977311ca2959eb1f6b7bd Mon Sep 17 00:00:00 2001 From: Iuri <689440+iuricmp@users.noreply.github.com> Date: Wed, 24 Jul 2024 16:31:03 +0100 Subject: [PATCH] chore: exposing ErrCode class (#158) Expose ErrCode class and add rpc_pb to exports. Useful for client who wants to implements error checks on their dApps, eg: ``` import { ErrCode } from "@gnolang/gnonative"; if (err.errCode() === ErrCode.ErrDecryptionFailed) { setError("Wrong password, please try again."); } ``` --------- Signed-off-by: Iuri Pereira <689440+iuricmp@users.noreply.github.com> Signed-off-by: D4ryl00 Co-authored-by: D4ryl00 --- expo/android/src/main/java/land/gno/gnonative/GoBridgeError.kt | 1 - .../src/main/java/land/gno/gnonative/JavaPromiseBlock.kt | 3 ++- expo/src/grpc/error.ts | 2 +- expo/src/index.ts | 2 ++ 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/expo/android/src/main/java/land/gno/gnonative/GoBridgeError.kt b/expo/android/src/main/java/land/gno/gnonative/GoBridgeError.kt index 6d9d52c9..874b8cf1 100644 --- a/expo/android/src/main/java/land/gno/gnonative/GoBridgeError.kt +++ b/expo/android/src/main/java/land/gno/gnonative/GoBridgeError.kt @@ -2,5 +2,4 @@ package land.gno.gnonative import expo.modules.kotlin.exception.CodedException class GoBridgeNotStartedError : CodedException("NotStarted", "Service hasn't started yet", null) -class GoBridgeCoreError(err: Exception?) : CodedException("CoreError", err) class GoBridgeCoreEOF : CodedException("EOF", "EOF", null) diff --git a/expo/android/src/main/java/land/gno/gnonative/JavaPromiseBlock.kt b/expo/android/src/main/java/land/gno/gnonative/JavaPromiseBlock.kt index 263a6bbc..6aaaba23 100644 --- a/expo/android/src/main/java/land/gno/gnonative/JavaPromiseBlock.kt +++ b/expo/android/src/main/java/land/gno/gnonative/JavaPromiseBlock.kt @@ -26,7 +26,8 @@ class PromiseBlock(val promise: Promise): IPromiseBlock { if (err?.message == "EOF") { this.promise.reject(GoBridgeCoreEOF()) } else { - this.promise.reject(GoBridgeCoreError(err)) + // Only the reject()'s message argument will be thrown to React Native, so put the error message in. + this.promise.reject("invoke method error", err?.message, null) } this.remove() // cleanup the promise diff --git a/expo/src/grpc/error.ts b/expo/src/grpc/error.ts index 3443c602..7262df1c 100644 --- a/expo/src/grpc/error.ts +++ b/expo/src/grpc/error.ts @@ -86,4 +86,4 @@ class GRPCError extends Error { } } -export { GRPCError }; +export { GRPCError, ErrCode }; diff --git a/expo/src/index.ts b/expo/src/index.ts index d555af24..1cad58ae 100644 --- a/expo/src/index.ts +++ b/expo/src/index.ts @@ -18,5 +18,7 @@ export function addChangeListener(listener: (event: ChangeEventPayload) => void) export { ChangeEventPayload, GnonativeView, GnonativeViewProps }; export * from './provider/gnonative-provider'; export * from '@buf/gnolang_gnonative.bufbuild_es/gnonativetypes_pb'; +export * from '@buf/gnolang_gnonative.bufbuild_es/rpc_pb'; +export { GRPCError } from './grpc/error'; export * from './api/GnoNativeApi';