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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user