Skip to content

Commit

Permalink
chore: exposing ErrCode class (#158)
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: D4ryl00 <[email protected]>
Co-authored-by: D4ryl00 <[email protected]>
  • Loading branch information
iuricmp and D4ryl00 authored Jul 24, 2024
1 parent c2d0989 commit aea0cd1
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion expo/src/grpc/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,4 @@ class GRPCError extends Error {
}
}

export { GRPCError };
export { GRPCError, ErrCode };
2 changes: 2 additions & 0 deletions expo/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

0 comments on commit aea0cd1

Please sign in to comment.