getDeviceFeedback method

Future<DeviceFeedbackResponse> getDeviceFeedback(
  1. String deviceId, {
  2. required String platformType,
  3. required String app,
})

Get device feedback code

deviceId - The device ID (androidId for Android, CERT_ID for iOS) platformType - The platform type (android, ios, windows, or linux) app - The app name to include in the API call

Returns the code from the device feedback API Throws DioException if the request fails

Implementation

Future<DeviceFeedbackResponse> getDeviceFeedback(
  String deviceId, {
  required String platformType,
  required String app,
}) async {
  DebugLogger.log('[AuthRemoteDataSource] === getDeviceFeedback() called ===');
  DebugLogger.log('[AuthRemoteDataSource] Device ID: $deviceId');
  DebugLogger.log('[AuthRemoteDataSource] Platform Type: $platformType');
  DebugLogger.log('[AuthRemoteDataSource] App: $app');

  // Use platform-specific endpoint with app as query parameter
  String endpoint;
  if (platformType == 'ios') {
    endpoint = '$baseUrl/ios/v1/devices/feedback/$deviceId?app=$app';
  } else if (platformType == 'macos'){
    endpoint = '$baseUrl/ios/v1/devices/feedback/$deviceId?app=$app';
  }else if (platformType == 'windows') {
    endpoint = '$baseUrl/win/v1/feedback/$deviceId?app=$app';
  } else if (platformType == 'linux') {
    endpoint = '$baseUrl/linux/v1/feedback/$deviceId?app=$app';
  } else {
    endpoint = '$baseUrl/android/v1/devicefeedback/$deviceId?app=$app';
  }

  DebugLogger.log('[AuthRemoteDataSource] API Endpoint: $endpoint');

  try {
    final response = await dio.get(endpoint);

    DebugLogger.log('[AuthRemoteDataSource] ✅ Device feedback API call successful');
    DebugLogger.log('[AuthRemoteDataSource] Response status: ${response.statusCode}');

    final feedbackResponse = DeviceFeedbackResponse.fromJson(response.data);
    DebugLogger.log('[AuthRemoteDataSource] Parsed response:');
    DebugLogger.log('[AuthRemoteDataSource]   - Status: ${feedbackResponse.status}');
    DebugLogger.log(
      '[AuthRemoteDataSource]   - Has data: ${feedbackResponse.data != null}',
    );
    DebugLogger.log('[AuthRemoteDataSource]   - Error: ${feedbackResponse.error}');

    if (feedbackResponse.data != null) {
      DebugLogger.log(
        '[AuthRemoteDataSource]   - Code length: ${feedbackResponse.data!.length} chars',
      );
    }

    return feedbackResponse;
  } on DioException catch (e) {
    DebugLogger.log('[AuthRemoteDataSource] ❌ DioException occurred');
    DebugLogger.log('[AuthRemoteDataSource] Error type: ${e.type}');
    DebugLogger.log('[AuthRemoteDataSource] Status code: ${e.response?.statusCode}');

    if (e.response?.statusCode == 400) {
      DebugLogger.log('[AuthRemoteDataSource] Handling 400 error - device not found');
      final errorData = e.response?.data;
      if (errorData is Map<String, dynamic>) {
        final feedbackResponse = DeviceFeedbackResponse.fromJson(errorData);
        DebugLogger.log('[AuthRemoteDataSource] Parsed error response:');
        DebugLogger.log(
          '[AuthRemoteDataSource]   - Status: ${feedbackResponse.status}',
        );
        DebugLogger.log('[AuthRemoteDataSource]   - Error: ${feedbackResponse.error}');
        return feedbackResponse;
      }
    }

    DebugLogger.log('[AuthRemoteDataSource] Rethrowing exception');
    rethrow;
  } catch (e) {
    DebugLogger.log('[AuthRemoteDataSource] ❌ Unexpected error: $e');
    rethrow;
  }
}