Othent
  • 👋Welcome to Othent
  • 🥪JS SDK
    • Getting Started
    • Events
    • Error Handling
    • Binary Data Types Utils
    • TypeScript Types
    • Config Constants
  • 🥪JS SDK API
    • constructor()
    • startTabSynching()
    • completeConnectionAfterRedirect()
    • connect()
    • disconnect()
    • requireAuth()
    • isAuthenticated
    • getActiveAddress()
    • getActivePublicKey()
    • getAllAddresses()
    • getWalletNames()
    • getUserDetails()
    • getSyncActiveAddress()
    • getSyncActivePublicKey()
    • getSyncAllAddresses()
    • getSyncWalletNames()
    • getSyncUserDetails()
    • sign() (transaction)
    • dispatch() (transaction)
    • encrypt()
    • decrypt()
    • signature()
    • signDataItem()
    • signMessage()
    • verifyMessage()
    • privateHash()
    • walletName
    • walletVersion
    • config
    • getArweaveConfig()
    • getPermissions()
  • Demos
    • 🍏SDK playground / demo
    • 🍏SDK playground / demo GitHub
    • 🍎File upload app example
    • 🍎File upload app example GitHub
  • 📚External libraries
    • arweave-js
    • Arweave Wallet Kit
  • Additional Links
    • 🌐Othent.io
    • 🌐Discord
    • 🌐GitHub
    • 🌐X
Powered by GitBook
On this page
  • throwErrors = false
  • OthentError
  1. JS SDK

Error Handling

Othent error handling.

All public Othent methods, except for the getters and properties, can throw an error when called under various circumstances, so you should wrap them in try-catch blocks and handle errors appropriately.

Note throwing errors (throwErrors: true) is the default behavior unless you explicitly set throwErrors: false. Also note that, for simplicity, all the examples in the docs use throwErrors: false.

import { Othent } from "@othent/kms";

const othent = new Othent({ appInfo, throwErrors: true, ... });

// ...

const throwAnError = async () => {
  try {
    // Make sure the user is authenticated, or prompt them to authenticate:
    await othent.requireAuth();

    // This will throw an error:
    await othent.sign({ foo: "bar" } as unknown as Transaction);
  } catch (err) {
    // TODO: Handle error...
  }
}

throwErrors = false

In this case, you must subscribe to error events using the addEventListener() function:

import { Othent } from "@othent/kms";

const othent = new Othent({ appInfo, throwErrors: false });

othent.addEventListener("error", (err) => {
  // TODO: Handle error...
});

// ...

const throwAnError = async () => {
  // Make sure the user is authenticated, or prompt them to authenticate:
  await othent.requireAuth();

  // This will throw an error:
  await othent.sign({ foo: "bar" } as unknown as Transaction);
}

OthentError

OthentError is a custom JS/TS class extending Error.

PreviousEventsNextBinary Data Types Utils

Last updated 8 months ago

Alternatively, you can set to let Othent wrap all functions (except for and ) in try-catch blocks automatically.

TODO: We are still working on this. We'll update the documentation soon. Track the progress on this in this .

🥪
throwErrors = false
startTabSynching
completeConnectionAfterRedirect
GitHub issue