nc-photos/lib/exception_util.dart

27 lines
915 B
Dart
Raw Normal View History

2021-04-10 12:28:12 +08:00
import 'dart:io';
2021-07-25 13:00:38 +08:00
import 'package:nc_photos/app_localizations.dart';
2021-04-10 12:28:12 +08: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
String toUserString(dynamic exception) {
2021-04-10 12:28:12 +08:00
if (exception is ApiException) {
if (exception.response.statusCode == 401) {
return L10n.global().errorUnauthenticated;
2021-10-07 00:56:43 +08:00
} else if (exception.response.statusCode == 404) {
return "404 not found";
2021-04-10 14:34:19 +08:00
} else if (exception.response.statusCode == 423) {
return L10n.global().errorLocked;
2021-05-28 12:37:15 +08:00
} else if (exception.response.statusCode == 500) {
return L10n.global().errorServerError;
2021-04-10 12:28:12 +08:00
}
} else if (exception is SocketException) {
return L10n.global().errorDisconnected;
2021-05-06 12:57:20 +08:00
} else if (exception is InvalidBaseUrlException) {
return L10n.global().errorInvalidBaseUrl;
2021-04-10 12:28:12 +08:00
}
return exception.toString();
}