feat: implement global error handling with reusable dialog and widget for improved user feedback

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
Nils-Johan Gynther
2026-04-30 12:01:47 +02:00
parent df1da1da2b
commit 5231ca42a7
6 changed files with 149 additions and 21 deletions
@@ -71,15 +71,18 @@ class ImportRepository {
}
final parsed = _parseResponse(response);
final items = (parsed['items'] as List?) ?? parsed as List?;
if (items == null) {
developer.log('Invalid response format: ${response.body}', name: 'ImportRepository', error: 'Invalid Data');
throw ApiException(type: ApiErrorType.unknown, message: 'Felaktigt svar från servern.');
// Check if the response is a ReceiptImportResult
if (parsed is Map<String, dynamic> && parsed.containsKey('items')) {
final items = (parsed['items'] as List?)?.map((e) => ParsedReceiptItem.fromJson(e)).toList();
if (items != null) {
developer.log('Successfully parsed ${items.length} items', name: 'ImportRepository');
return items;
}
}
developer.log('Successfully parsed ${items.length} items', name: 'ImportRepository');
return items.map((e) => ParsedReceiptItem.fromJson(e as Map<String, dynamic>)).toList();
developer.log('Invalid response format: ${response.body}', name: 'ImportRepository', error: 'Invalid Data');
throw ApiException(type: ApiErrorType.unknown, message: 'Felaktigt svar från servern.');
} catch (e) {
developer.log('Exception during receipt import: $e', name: 'ImportRepository', error: e);
rethrow;