ServiceResult<T>.fromPlatformException constructor

ServiceResult<T>.fromPlatformException(
  1. PlatformException e
)

Factory constructor để tạo một ServiceResult từ một PlatformException. Điều này giúp chuyển đổi lỗi từ lớp native sang lớp kết quả một cách nhất quán.

Implementation

factory ServiceResult.fromPlatformException(PlatformException e) {
  final status = _mapErrorCodeToStatus(e.code);
  final details = e.details as Map<dynamic, dynamic>?;

  return ServiceResult.failure(
    status: status,
    message: e.message ?? status.description,
    sw1: details?['sw1'] as int?,
    sw2: details?['sw2'] as int?,
  );
}