From d8952a4fbc0bb9f01668164d4d33eecda284ab07 Mon Sep 17 00:00:00 2001 From: Pratik-canopas Date: Wed, 22 Jan 2025 11:55:12 +0530 Subject: [PATCH] Fix google drive permission error --- app/assets/locales/app_en.arb | 1 + .../domain/extensions/app_error_extensions.dart | 2 ++ data/lib/errors/app_error.dart | 17 ++++++++++++++++- data/lib/errors/l10n_error_codes.dart | 1 + 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/assets/locales/app_en.arb b/app/assets/locales/app_en.arb index d384b970..efa8972f 100644 --- a/app/assets/locales/app_en.arb +++ b/app/assets/locales/app_en.arb @@ -40,6 +40,7 @@ "back_up_folder_not_found_error": "Back up folder not found!", "auth_session_expired_error": "Your session has expired. Please log in again to continue using the app.", "save_media_in_gallery_error": "There was an issue saving your media to the gallery. Please try again, we’ll have it sorted out shortly", + "no_google_drive_access_error": "It seems we don’t have the required permissions to access your Google Drive. Please sign in again and grant the necessary permissions.", "@_MEDIA_ACTIONS":{}, "upload_to_google_drive_title": "Upload to Google Drive", diff --git a/app/lib/domain/extensions/app_error_extensions.dart b/app/lib/domain/extensions/app_error_extensions.dart index 3a646448..4caeb903 100644 --- a/app/lib/domain/extensions/app_error_extensions.dart +++ b/app/lib/domain/extensions/app_error_extensions.dart @@ -21,6 +21,8 @@ extension AppErrorExtensions on Object { return context.l10n.auth_session_expired_error; case AppErrorL10nCodes.unableToSaveFileInGalleryError: return context.l10n.save_media_in_gallery_error; + case AppErrorL10nCodes.noGoogleDriveAccessError: + return context.l10n.no_google_drive_access_error; default: return context.l10n.something_went_wrong_error; } diff --git a/data/lib/errors/app_error.dart b/data/lib/errors/app_error.dart index aadd9e37..5c59e7f5 100644 --- a/data/lib/errors/app_error.dart +++ b/data/lib/errors/app_error.dart @@ -1,4 +1,5 @@ import 'dart:io'; +import 'package:flutter/services.dart'; import 'l10n_error_codes.dart'; import 'package:dio/dio.dart' show DioException; @@ -17,9 +18,14 @@ class AppError implements Exception { factory AppError.fromError(Object error) { if (error is AppError) { return error; - } else if (error is SocketException) { + } else if (error is SocketException || + (error is PlatformException && error.code == 'network_error')) { return const NoConnectionError(); } else if (error is DioException) { + if (error.response?.statusCode == 403 && + error.requestOptions.uri.host == 'www.googleapis.com') { + return NoGoogleDriveAccessError(); + } return SomethingWentWrongError( message: error.message, statusCode: error.response?.statusCode, @@ -71,6 +77,15 @@ class SomethingWentWrongError extends AppError { ); } +class NoGoogleDriveAccessError extends AppError { + const NoGoogleDriveAccessError() + : super( + l10nCode: AppErrorL10nCodes.noGoogleDriveAccessError, + message: + "It seems we don’t have the required permissions to access your Google Drive. Please sign in again and grant the necessary permissions.", + ); +} + class DropboxAuthSessionExpiredError extends AppError { const DropboxAuthSessionExpiredError() : super( diff --git a/data/lib/errors/l10n_error_codes.dart b/data/lib/errors/l10n_error_codes.dart index 434426de..633ad68f 100644 --- a/data/lib/errors/l10n_error_codes.dart +++ b/data/lib/errors/l10n_error_codes.dart @@ -6,4 +6,5 @@ class AppErrorL10nCodes { static const backUpFolderNotFoundError = 'back-up-folder-not-found'; static const unableToSaveFileInGalleryError = 'unable-to-save-file-in-gallery'; + static const noGoogleDriveAccessError = 'no-google-drive-access'; }