augment-vir - v31.13.0
    Preparing search index...

    Function ensureErrorClass

    • Ensures that the given originalError is an instance of the given errorClass.

      • If it is, originalError is directly returned.
      • If it is not, a new instance of errorClass is constructed with the given parameters.

      Type Parameters

      • const ErrorClass extends Constructor<Error>

      Parameters

      Returns InstanceType<ErrorClass>

      import {ensureErrorClass, extractErrorMessage} from '@augment-vir/common';

      class MyCustomError extends Error {
      public override readonly name = 'MyCustomError';
      }

      try {
      // do some stuff
      } catch (error) {
      throw ensureErrorClass(error, MyCustomError, extractErrorMessage(error));
      }