2021-04-10 06:28:12 +02:00
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
import 'package:flutter/widgets.dart';
|
|
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|
|
|
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, BuildContext context) {
|
|
|
|
if (exception is ApiException) {
|
|
|
|
if (exception.response.statusCode == 401) {
|
|
|
|
return AppLocalizations.of(context).errorUnauthenticated;
|
2021-04-10 08:34:19 +02:00
|
|
|
} else if (exception.response.statusCode == 423) {
|
|
|
|
return AppLocalizations.of(context).errorLocked;
|
2021-04-10 06:28:12 +02:00
|
|
|
}
|
|
|
|
} else if (exception is SocketException) {
|
|
|
|
return AppLocalizations.of(context).errorDisconnected;
|
2021-05-06 06:57:20 +02:00
|
|
|
} else if (exception is InvalidBaseUrlException) {
|
|
|
|
return AppLocalizations.of(context).errorInvalidBaseUrl;
|
2021-04-10 06:28:12 +02:00
|
|
|
}
|
|
|
|
return exception.toString();
|
|
|
|
}
|