Errors

Errors

Whenever an error occurs in a process, SecrecyClient throws an "error". This error contains all the information that you need to handle the error in the client. The SecrecyClient defines a list of error codes that each represent a different type of error.

Error Handling

As you can see in our example, if an error occurs during the call, the function checks if the error is an instance of SecrecyError by using a helper function isSecrecyError. If so, you can access the properties returned by the SecrecyError object such as code, message and name properties of the error, which can help in debugging issues related to the API call. You can view all properties of the error object in the SecrecyError api section.

const handlingSecrecyError = async (): Promise<SelfUser | undefined> => {
  if (!secrecyClient) {
    throw 'No client';
  }
 
  try {
    // whatever the Secrecy methods
    const user = await secrecyClient.me();
    return user;
  } catch (e) {
    // Check if the error is a SecrecyError
    if (isSecrecyError(e)) {
      const { message, code, name } = e;
      console.error({ message, code, name });
    }
  }
};