fromPlatformException static method

AlarmException fromPlatformException(
  1. PlatformException ex
)

Wraps a PlatformException within an AlarmException.

Implementation

static AlarmException fromPlatformException(PlatformException ex) {
  return AlarmException(
    ex.code == 'channel-error'
        ? AlarmErrorCode.channelError
        : AlarmErrorCode.values.firstWhere(
            (e) => e.index == (int.tryParse(ex.code) ?? 0),
            orElse: () => AlarmErrorCode.unknown,
          ),
    message: ex.message,
    stacktrace: ex.stacktrace,
  );
}