2021-04-10 06:28:12 +02:00
|
|
|
import 'dart:io';
|
|
|
|
|
2021-07-25 07:00:38 +02:00
|
|
|
import 'package:nc_photos/app_localizations.dart';
|
2021-04-10 06:28:12 +02:00
|
|
|
import 'package:nc_photos/exception.dart';
|
|
|
|
|
|
|
|
/// Convert an exception to a user-facing string
|
|
|
|
///
|
|
|
|
/// Typically used with SnackBar to show a proper error message
|
2021-08-29 13:51:43 +02:00
|
|
|
String toUserString(dynamic exception) {
|
2021-04-10 06:28:12 +02:00
|
|
|
if (exception is ApiException) {
|
|
|
|
if (exception.response.statusCode == 401) {
|
2021-08-29 13:51:43 +02:00
|
|
|
return L10n.global().errorUnauthenticated;
|
2021-04-10 08:34:19 +02:00
|
|
|
} else if (exception.response.statusCode == 423) {
|
2021-08-29 13:51:43 +02:00
|
|
|
return L10n.global().errorLocked;
|
2021-05-28 06:37:15 +02:00
|
|
|
} else if (exception.response.statusCode == 500) {
|
2021-08-29 13:51:43 +02:00
|
|
|
return L10n.global().errorServerError;
|
2021-04-10 06:28:12 +02:00
|
|
|
}
|
|
|
|
} else if (exception is SocketException) {
|
2021-08-29 13:51:43 +02:00
|
|
|
return L10n.global().errorDisconnected;
|
2021-05-06 06:57:20 +02:00
|
|
|
} else if (exception is InvalidBaseUrlException) {
|
2021-08-29 13:51:43 +02:00
|
|
|
return L10n.global().errorInvalidBaseUrl;
|
2021-04-10 06:28:12 +02:00
|
|
|
}
|
|
|
|
return exception.toString();
|
|
|
|
}
|