Skip to content

Commit 8228d97

Browse files
committed
store [nfc]: Move some declarations up out of a switch case
And rethrow AccountNotFoundExceptions in an explicit `on` block, rather than in the `default` case of this `switch`. (Otherwise the account-exists check would throw.)
1 parent e13084a commit 8228d97

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/model/store.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,16 @@ abstract class GlobalStore extends ChangeNotifier {
192192
final PerAccountStore store;
193193
try {
194194
store = await doLoadPerAccount(accountId);
195+
} on AccountNotFoundException {
196+
rethrow;
195197
} catch (e) {
198+
final account = getAccount(accountId);
199+
assert(account != null); // doLoadPerAccount would have thrown AccountNotFoundException
200+
final zulipLocalizations = GlobalLocalizations.zulipLocalizations;
196201
switch (e) {
197202
case HttpException(httpStatus: 401):
198203
// The API key is invalid and the store can never be loaded
199204
// unless the user retries manually.
200-
final account = getAccount(accountId);
201-
assert(account != null); // doLoadPerAccount would have thrown AccountNotFoundException
202-
final zulipLocalizations = GlobalLocalizations.zulipLocalizations;
203205
reportErrorToUserModally(
204206
zulipLocalizations.errorCouldNotConnectTitle,
205207
message: zulipLocalizations.errorInvalidApiKeyMessage(

0 commit comments

Comments
 (0)