wrap static method

OtpCryptoException wrap(
  1. Object error, {
  2. required String code,
  3. required String message,
  4. StackTrace? stackTrace,
})

Wraps any error as an OtpCryptoException with the given code and generic message. If error is already an OtpCryptoException, it is returned unchanged.

HINT: Use in catch blocks to ensure uniform, safe error reporting.

Implementation

static OtpCryptoException wrap(
  Object error, {
  required String code,
  required String message,
  StackTrace? stackTrace,
}) {
  if (error is OtpCryptoException) return error;
  return OtpCryptoException(
    code,
    message,
    cause: error,
    stackTrace: stackTrace,
  );
}