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

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

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.

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

Last updated