mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-22 16:56:19 +01:00
23 lines
862 B
Dart
23 lines
862 B
Dart
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;
|
|
} else if (exception.response.statusCode == 423) {
|
|
return AppLocalizations.of(context).errorLocked;
|
|
}
|
|
} else if (exception is SocketException) {
|
|
return AppLocalizations.of(context).errorDisconnected;
|
|
} else if (exception is InvalidBaseUrlException) {
|
|
return AppLocalizations.of(context).errorInvalidBaseUrl;
|
|
}
|
|
return exception.toString();
|
|
}
|