mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-02 06:46:22 +01:00
Improve error message for wrong password
This commit is contained in:
parent
eaf3824400
commit
5068fc8a01
4 changed files with 28 additions and 8 deletions
|
@ -80,8 +80,9 @@ Future<String> exchangePassword(Account account) async {
|
||||||
} else {
|
} else {
|
||||||
_log.severe(
|
_log.severe(
|
||||||
"[exchangePassword] Failed while requesting app password: $response");
|
"[exchangePassword] Failed while requesting app password: $response");
|
||||||
throw HttpException(
|
throw ApiException(
|
||||||
"Failed communicating with server: ${response.statusCode}");
|
response: response,
|
||||||
|
message: "Failed communicating with server: ${response.statusCode}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,8 +77,14 @@ class AppPasswordExchangeBloc
|
||||||
_log.warning("[_exchangePassword] Invalid base url");
|
_log.warning("[_exchangePassword] Invalid base url");
|
||||||
yield AppPasswordExchangeBlocFailure(e);
|
yield AppPasswordExchangeBlocFailure(e);
|
||||||
} catch (e, stacktrace) {
|
} catch (e, stacktrace) {
|
||||||
_log.shout("[_exchangePassword] Failed while exchanging password", e,
|
if (e is ApiException && e.response.statusCode == 401) {
|
||||||
stacktrace);
|
// wrong password, normal
|
||||||
|
_log.warning(
|
||||||
|
"[_exchangePassword] Server response 401, wrong password?");
|
||||||
|
} else {
|
||||||
|
_log.shout("[_exchangePassword] Failed while exchanging password", e,
|
||||||
|
stacktrace);
|
||||||
|
}
|
||||||
yield AppPasswordExchangeBlocFailure(e);
|
yield AppPasswordExchangeBlocFailure(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -383,5 +383,9 @@
|
||||||
"errorInvalidBaseUrl": "Unable to communicate. Please make sure the address is the base URL of your Nextcloud instance",
|
"errorInvalidBaseUrl": "Unable to communicate. Please make sure the address is the base URL of your Nextcloud instance",
|
||||||
"@errorInvalidBaseUrl": {
|
"@errorInvalidBaseUrl": {
|
||||||
"description": "Error message when the base URL is invalid"
|
"description": "Error message when the base URL is invalid"
|
||||||
|
},
|
||||||
|
"errorWrongPassword": "Unable to authenticate. Please double check the username and password",
|
||||||
|
"@errorWrongPassword": {
|
||||||
|
"description": "Error message when the username or password is wrong"
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -6,6 +6,7 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
import 'package:nc_photos/account.dart';
|
import 'package:nc_photos/account.dart';
|
||||||
import 'package:nc_photos/bloc/app_password_exchange.dart';
|
import 'package:nc_photos/bloc/app_password_exchange.dart';
|
||||||
|
import 'package:nc_photos/exception.dart';
|
||||||
import 'package:nc_photos/exception_util.dart' as exception_util;
|
import 'package:nc_photos/exception_util.dart' as exception_util;
|
||||||
import 'package:nc_photos/k.dart' as k;
|
import 'package:nc_photos/k.dart' as k;
|
||||||
import 'package:nc_photos/snack_bar_manager.dart';
|
import 'package:nc_photos/snack_bar_manager.dart';
|
||||||
|
@ -95,10 +96,18 @@ class _ConnectState extends State<Connect> {
|
||||||
_log.info("[_onStateChange] Account is good: $newAccount");
|
_log.info("[_onStateChange] Account is good: $newAccount");
|
||||||
Navigator.of(context).pop(newAccount);
|
Navigator.of(context).pop(newAccount);
|
||||||
} else if (state is AppPasswordExchangeBlocFailure) {
|
} else if (state is AppPasswordExchangeBlocFailure) {
|
||||||
SnackBarManager().showSnackBar(SnackBar(
|
if (state.exception is ApiException &&
|
||||||
content: Text(exception_util.toUserString(state.exception, context)),
|
(state.exception as ApiException).response.statusCode == 401) {
|
||||||
duration: k.snackBarDurationNormal,
|
SnackBarManager().showSnackBar(SnackBar(
|
||||||
));
|
content: Text(AppLocalizations.of(context).errorWrongPassword),
|
||||||
|
duration: k.snackBarDurationNormal,
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
SnackBarManager().showSnackBar(SnackBar(
|
||||||
|
content: Text(exception_util.toUserString(state.exception, context)),
|
||||||
|
duration: k.snackBarDurationNormal,
|
||||||
|
));
|
||||||
|
}
|
||||||
Navigator.of(context).pop(null);
|
Navigator.of(context).pop(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue