Skip to content

Commit c39ecf1

Browse files
committed
login: Show more information on login failure
In particular, this means we'll show messages from the server like "Your username or password is incorrect" or "Enter a valid email address." Fixes-partly: zulip#105
1 parent 0e5067a commit c39ecf1

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lib/widgets/login.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:flutter/material.dart';
22

33
import '../api/core.dart';
4+
import '../api/exception.dart';
45
import '../api/route/account.dart';
56
import '../api/route/realm.dart';
67
import '../api/route/users.dart';
@@ -155,7 +156,7 @@ class _AddAccountPageState extends State<AddAccountPage> {
155156
return;
156157
}
157158
// TODO(#105) give more helpful feedback; see `fetchServerSettings`
158-
// in zulip-mobile's src/message/fetchActions.js. Needs #37.
159+
// in zulip-mobile's src/message/fetchActions.js.
159160
showErrorDialog(context: context,
160161
title: 'Could not connect', message: 'Failed to connect to server:\n$url');
161162
return;
@@ -279,12 +280,15 @@ class _PasswordLoginPageState extends State<PasswordLoginPage> {
279280
try {
280281
result = await fetchApiKey(
281282
realmUrl: realmUrl, username: username, password: password);
282-
} on Exception { // TODO(#37): distinguish API exceptions
283+
} on ApiRequestException catch (e) {
283284
if (!context.mounted) return;
284-
// TODO(#105) give more helpful feedback. Needs #37. The RN app is
285+
// TODO(#105) give more helpful feedback. The RN app is
285286
// unhelpful here; we should at least recognize invalid auth errors, and
286287
// errors for deactivated user or realm (see zulip-mobile#4571).
287-
showErrorDialog(context: context, title: 'Login failed');
288+
final message = (e is ZulipApiException)
289+
? 'The server said:\n\n${e.message}'
290+
: e.message;
291+
showErrorDialog(context: context, title: 'Login failed', message: message);
288292
return;
289293
}
290294

0 commit comments

Comments
 (0)