jsErrorWrap<T> function

T jsErrorWrap<T>(
  1. T callback()
)

Wraps any callback to convert JSErrors to SodiumExceptions.

This simply runs the callback and catches all instances of JSError and rethrows the JSError.message as SodiumException.

Implementation

T jsErrorWrap<T>(T Function() callback) {
  try {
    return callback();
  } catch (e, s) {
    if (e.isA<JSError>()) {
      Error.throwWithStackTrace(SodiumException((e as JSError).message), s);
    } else {
      Error.throwWithStackTrace(SodiumException(e.toString()), s);
    }
  }
}