Skip to content

Commit

Permalink
Fix google drive permission error
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-pratik-k committed Jan 22, 2025
1 parent 3581f68 commit d8952a4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/assets/locales/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions app/lib/domain/extensions/app_error_extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
17 changes: 16 additions & 1 deletion data/lib/errors/app_error.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:io';
import 'package:flutter/services.dart';
import 'l10n_error_codes.dart';
import 'package:dio/dio.dart' show DioException;

Expand All @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions data/lib/errors/l10n_error_codes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

0 comments on commit d8952a4

Please sign in to comment.