Add Dio timeouts and map backend errors to user-friendly messages

Set 5s/15s/15s connect/receive/send timeouts so calls fail fast instead of
hanging. Introduce dioErrorToUserMessage() and route DioException-throwing
call sites (device actions, devices list, notifications list, scanners
status card) through it, replacing raw e.toString() output. Notifications
list now surfaces load errors inline in the theme's error color, matching
the devices list pattern. Status dots show the mapped detail as a tooltip.
Stop logging the API key in cleartext.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
rzuasti
2026-05-31 09:06:56 -04:00
co-authored by Claude Opus 4.7
parent 0f6296759d
commit 7954a9c755
5 changed files with 104 additions and 28 deletions
+27 -5
View File
@@ -44,6 +44,7 @@ class _NotificationsListState extends State<NotificationsList> with RouteAware {
List<oott_model.Notification> _items = [];
bool _isLoading = false;
bool _hasNextPage = false;
String? _error;
@override
void initState() {
@@ -78,10 +79,16 @@ class _NotificationsListState extends State<NotificationsList> with RouteAware {
Future<void> _fetchPage(int page) async {
if (_isLoading) return;
setState(() => _isLoading = true);
setState(() {
_isLoading = true;
_error = null;
});
try {
final results = await BackendAPI.instance
.listNotifications(_filter.isNew, page * _pageSize, limit: _pageSize + 1);
final results = await BackendAPI.instance.listNotifications(
_filter.isNew,
page * _pageSize,
limit: _pageSize + 1,
);
if (!mounted) return;
setState(() {
_currentPage = page;
@@ -89,9 +96,12 @@ class _NotificationsListState extends State<NotificationsList> with RouteAware {
_items = _hasNextPage ? results.take(_pageSize).toList() : results;
_isLoading = false;
});
} catch (_) {
} catch (e) {
if (!mounted) return;
setState(() => _isLoading = false);
setState(() {
_error = dioErrorToUserMessage(e);
_isLoading = false;
});
}
}
@@ -205,6 +215,18 @@ class _NotificationsListState extends State<NotificationsList> with RouteAware {
),
];
}
if (_error != null) {
return [
SliverFillRemaining(
child: Center(
child: Text(
'Error: $_error',
style: TextStyle(color: Theme.of(context).colorScheme.error),
),
),
),
];
}
if (_items.isEmpty) {
return [
SliverToBoxAdapter(