|
|
@ -11,9 +11,9 @@ import 'package:neon/src/utils/exceptions.dart'; |
|
|
|
import 'package:neon/src/utils/provider.dart'; |
|
|
|
import 'package:neon/src/utils/provider.dart'; |
|
|
|
import 'package:nextcloud/nextcloud.dart'; |
|
|
|
import 'package:nextcloud/nextcloud.dart'; |
|
|
|
|
|
|
|
|
|
|
|
class NeonException extends StatelessWidget { |
|
|
|
class NeonError extends StatelessWidget { |
|
|
|
const NeonException( |
|
|
|
const NeonError( |
|
|
|
this.exception, { |
|
|
|
this.error, { |
|
|
|
required this.onRetry, |
|
|
|
required this.onRetry, |
|
|
|
this.onlyIcon = false, |
|
|
|
this.onlyIcon = false, |
|
|
|
this.iconSize, |
|
|
|
this.iconSize, |
|
|
@ -21,14 +21,14 @@ class NeonException extends StatelessWidget { |
|
|
|
super.key, |
|
|
|
super.key, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
final dynamic exception; |
|
|
|
final dynamic error; |
|
|
|
final VoidCallback onRetry; |
|
|
|
final VoidCallback onRetry; |
|
|
|
final bool onlyIcon; |
|
|
|
final bool onlyIcon; |
|
|
|
final double? iconSize; |
|
|
|
final double? iconSize; |
|
|
|
final Color? color; |
|
|
|
final Color? color; |
|
|
|
|
|
|
|
|
|
|
|
static void showSnackbar(final BuildContext context, final dynamic exception) { |
|
|
|
static void showSnackbar(final BuildContext context, final dynamic error) { |
|
|
|
final details = getDetails(context, exception); |
|
|
|
final details = getDetails(context, error); |
|
|
|
|
|
|
|
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar( |
|
|
|
ScaffoldMessenger.of(context).showSnackBar( |
|
|
|
SnackBar( |
|
|
|
SnackBar( |
|
|
@ -45,11 +45,11 @@ class NeonException extends StatelessWidget { |
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
@override |
|
|
|
Widget build(final BuildContext context) { |
|
|
|
Widget build(final BuildContext context) { |
|
|
|
if (exception == null) { |
|
|
|
if (error == null) { |
|
|
|
return const SizedBox(); |
|
|
|
return const SizedBox(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
final details = getDetails(context, exception); |
|
|
|
final details = getDetails(context, error); |
|
|
|
final color = this.color ?? Theme.of(context).colorScheme.error; |
|
|
|
final color = this.color ?? Theme.of(context).colorScheme.error; |
|
|
|
|
|
|
|
|
|
|
|
final errorIcon = Icon( |
|
|
|
final errorIcon = Icon( |
|
|
@ -111,71 +111,71 @@ class NeonException extends StatelessWidget { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@internal |
|
|
|
@internal |
|
|
|
static ExceptionDetails getDetails(final BuildContext context, final dynamic exception) { |
|
|
|
static ExceptionDetails getDetails(final BuildContext context, final dynamic error) { |
|
|
|
if (exception is String) { |
|
|
|
if (error is String) { |
|
|
|
return ExceptionDetails( |
|
|
|
return ExceptionDetails( |
|
|
|
text: exception, |
|
|
|
text: error, |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (exception is MissingPermissionException) { |
|
|
|
if (error is MissingPermissionException) { |
|
|
|
return ExceptionDetails( |
|
|
|
return ExceptionDetails( |
|
|
|
text: AppLocalizations.of(context).errorMissingPermission(exception.permission.toString().split('.')[1]), |
|
|
|
text: AppLocalizations.of(context).errorMissingPermission(error.permission.toString().split('.')[1]), |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (exception is UnableToOpenFileException) { |
|
|
|
if (error is UnableToOpenFileException) { |
|
|
|
return ExceptionDetails( |
|
|
|
return ExceptionDetails( |
|
|
|
text: AppLocalizations.of(context).errorUnableToOpenFile, |
|
|
|
text: AppLocalizations.of(context).errorUnableToOpenFile, |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (exception is InvalidQRcodeException) { |
|
|
|
if (error is InvalidQRcodeException) { |
|
|
|
return ExceptionDetails( |
|
|
|
return ExceptionDetails( |
|
|
|
text: AppLocalizations.of(context).errorInvalidQRcode, |
|
|
|
text: AppLocalizations.of(context).errorInvalidQRcode, |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (exception is DynamiteApiException) { |
|
|
|
if (error is DynamiteApiException) { |
|
|
|
if (exception.statusCode == 401) { |
|
|
|
if (error.statusCode == 401) { |
|
|
|
return ExceptionDetails( |
|
|
|
return ExceptionDetails( |
|
|
|
text: AppLocalizations.of(context).errorCredentialsForAccountNoLongerMatch, |
|
|
|
text: AppLocalizations.of(context).errorCredentialsForAccountNoLongerMatch, |
|
|
|
isUnauthorized: true, |
|
|
|
isUnauthorized: true, |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (exception.statusCode >= 500 && exception.statusCode <= 599) { |
|
|
|
if (error.statusCode >= 500 && error.statusCode <= 599) { |
|
|
|
return ExceptionDetails( |
|
|
|
return ExceptionDetails( |
|
|
|
text: AppLocalizations.of(context).errorServerHadAProblemProcessingYourRequest, |
|
|
|
text: AppLocalizations.of(context).errorServerHadAProblemProcessingYourRequest, |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (exception is SocketException) { |
|
|
|
if (error is SocketException) { |
|
|
|
return ExceptionDetails( |
|
|
|
return ExceptionDetails( |
|
|
|
text: exception.address != null |
|
|
|
text: error.address != null |
|
|
|
? AppLocalizations.of(context).errorUnableToReachServerAt(exception.address!.host) |
|
|
|
? AppLocalizations.of(context).errorUnableToReachServerAt(error.address!.host) |
|
|
|
: AppLocalizations.of(context).errorUnableToReachServer, |
|
|
|
: AppLocalizations.of(context).errorUnableToReachServer, |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (exception is ClientException) { |
|
|
|
if (error is ClientException) { |
|
|
|
return ExceptionDetails( |
|
|
|
return ExceptionDetails( |
|
|
|
text: exception.uri != null |
|
|
|
text: error.uri != null |
|
|
|
? AppLocalizations.of(context).errorUnableToReachServerAt(exception.uri!.host) |
|
|
|
? AppLocalizations.of(context).errorUnableToReachServerAt(error.uri!.host) |
|
|
|
: AppLocalizations.of(context).errorUnableToReachServer, |
|
|
|
: AppLocalizations.of(context).errorUnableToReachServer, |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (exception is HttpException) { |
|
|
|
if (error is HttpException) { |
|
|
|
return ExceptionDetails( |
|
|
|
return ExceptionDetails( |
|
|
|
text: exception.uri != null |
|
|
|
text: error.uri != null |
|
|
|
? AppLocalizations.of(context).errorUnableToReachServerAt(exception.uri!.host) |
|
|
|
? AppLocalizations.of(context).errorUnableToReachServerAt(error.uri!.host) |
|
|
|
: AppLocalizations.of(context).errorUnableToReachServer, |
|
|
|
: AppLocalizations.of(context).errorUnableToReachServer, |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (exception is TimeoutException) { |
|
|
|
if (error is TimeoutException) { |
|
|
|
return ExceptionDetails( |
|
|
|
return ExceptionDetails( |
|
|
|
text: AppLocalizations.of(context).errorConnectionTimedOut, |
|
|
|
text: AppLocalizations.of(context).errorConnectionTimedOut, |
|
|
|
); |
|
|
|
); |