• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wger-project / flutter / 14928341503

09 May 2025 11:54AM UTC coverage: 52.925% (-3.5%) from 56.402%
14928341503

Pull #813

github

rolandgeider
Catch and handle WgerHttpException specially

This shows the server errors directly in the form, instead of a modal dialog
(which is the default for all the other forms and places that throw the exception)
Pull Request #813: Improve error handling and logging

108 of 325 new or added lines in 14 files covered. (33.23%)

100 existing lines in 2 files now uncovered.

5147 of 9725 relevant lines covered (52.93%)

1.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

55.56
/lib/exceptions/http_exception.dart
1
/*
2
 * This file is part of wger Workout Manager <https://github.com/wger-project>.
3
 * Copyright (C) 2020, 2021 wger Team
4
 *
5
 * wger Workout Manager is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU Affero General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU Affero General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Affero General Public License
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18

19
import 'dart:convert';
20

21
class WgerHttpException implements Exception {
22
  Map<String, dynamic> errors = {};
23

24
  /// Custom http exception.
25
  /// Expects the response body of the REST call and will try to parse it to
26
  /// JSON. Will use the response as-is if it fails.
27
  WgerHttpException(dynamic responseBody) {
2✔
28
    if (responseBody == null) {
29
      errors = {'unknown_error': 'An unknown error occurred, no further information available'};
×
30
    } else {
31
      try {
32
        final response = json.decode(responseBody);
2✔
33
        errors = (response is Map ? response : {'unknown_error': response}).cast<String, dynamic>();
6✔
34
      } catch (e) {
35
        errors = {'unknown_error': responseBody};
×
36
      }
37
    }
38
  }
39

40
  WgerHttpException.fromMap(Map<String, dynamic> map) {
1✔
41
    errors = map;
1✔
42
  }
43

UNCOV
44
  @override
×
45
  String toString() {
NEW
46
    return errors.values.toList().join(', ');
×
47
  }
48
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc