D-ID Client SDK - v3.0.0-0
    Preparing search index...

    Function isDIDError

    • Type guard that reports whether a caught value is an error raised by the SDK.

      It accepts any Error carrying a string kind, which every BaseError has, so it also recognizes SDK errors that crossed a bundle boundary, where instanceof BaseError can fail because two copies of the class are loaded. It narrows to DIDError, the union of the seven subclasses, so a switch on kind inside the branch narrows further to one class and its own fields — error.status on an HttpError, error.key on a ValidationError.

      The duck-typing is wider than the union it promises, so keep the default branch of a switch total — DIDError says why.

      Parameters

      • error: unknown

        The caught value to test.

      Returns error is DIDError

      true when error is an error the SDK raised.

      try {
      await agentManager.chat('What is the distance to the moon?');
      } catch (error) {
      if (isDIDError(error)) {
      console.error(error.kind, error.toJson());

      if (error.kind === 'HttpError' && error.status === 401) {
      refreshCredentials();
      }
      } else {
      throw error;
      }
      }