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.

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.

Last updated