From 648c4a0853c8e82d3bd1d9e8685d127a993250c6 Mon Sep 17 00:00:00 2001 From: tamslo Date: Wed, 13 Nov 2024 18:48:41 +0100 Subject: [PATCH] refactor(#660): response error handling in parent lab class --- app/ios/Runner.xcodeproj/project.pbxproj | 6 +++--- app/lib/login/models/lab.dart | 12 +++++++++--- .../models/oauth_authorization_code_flow_lab.dart | 10 +--------- app/pubspec.lock | 4 ++-- app/pubspec.yaml | 2 +- 5 files changed, 16 insertions(+), 18 deletions(-) diff --git a/app/ios/Runner.xcodeproj/project.pbxproj b/app/ios/Runner.xcodeproj/project.pbxproj index 4bc8cd95..96a33dca 100644 --- a/app/ios/Runner.xcodeproj/project.pbxproj +++ b/app/ios/Runner.xcodeproj/project.pbxproj @@ -360,7 +360,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; - DEVELOPMENT_TEAM = ML9QV973KL; + DEVELOPMENT_TEAM = H4NQ8HX57R; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( @@ -495,7 +495,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; - DEVELOPMENT_TEAM = ML9QV973KL; + DEVELOPMENT_TEAM = H4NQ8HX57R; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( @@ -525,7 +525,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; - DEVELOPMENT_TEAM = ML9QV973KL; + DEVELOPMENT_TEAM = H4NQ8HX57R; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( diff --git a/app/lib/login/models/lab.dart b/app/lib/login/models/lab.dart index 29c4102b..26dd20ab 100644 --- a/app/lib/login/models/lab.dart +++ b/app/lib/login/models/lab.dart @@ -1,6 +1,6 @@ import 'dart:convert'; -import 'package:http/http.dart'; +import 'package:http/http.dart' as http; import '../../common/module.dart'; @@ -24,11 +24,17 @@ class Lab { throw UnimplementedError(); } - (List, List) labDataFromHTTPResponse(Response response) { + Future<(List, List)> fetchData( + Uri dataUrl, + { + Map? headers, + }) async { + final response = await http.get(dataUrl, headers: headers); + if (response.statusCode != 200) throw Exception(); final json = jsonDecode(response.body) as Map; final labData = json['diplotypes'].map( LabResult.fromJson - ).toList(); + ).toList() as List; var activeDrugs = []; if (json.containsKey('medications')) { activeDrugs = List.from(json['medications']); diff --git a/app/lib/login/models/oauth_authorization_code_flow_lab.dart b/app/lib/login/models/oauth_authorization_code_flow_lab.dart index 8b954edb..dc97f373 100644 --- a/app/lib/login/models/oauth_authorization_code_flow_lab.dart +++ b/app/lib/login/models/oauth_authorization_code_flow_lab.dart @@ -56,14 +56,6 @@ class OAuthAuthorizationCodeFlowLab extends Lab { @override Future<(List, List)> loadData() async { - final response = await http.get( - dataUrl, - headers: {'Authorization': 'Bearer $token'}, - ); - if (response.statusCode == 200) { - return labDataFromHTTPResponse(response); - } else { - throw Exception(); - } + return fetchData(dataUrl, headers: {'Authorization': 'Bearer $token'}); } } \ No newline at end of file diff --git a/app/pubspec.lock b/app/pubspec.lock index 78b3f23f..b13eda8d 100644 --- a/app/pubspec.lock +++ b/app/pubspec.lock @@ -154,10 +154,10 @@ packages: dependency: "direct dev" description: name: build_runner - sha256: dd09dd4e2b078992f42aac7f1a622f01882a8492fef08486b27ddde929c19f04 + sha256: "028819cfb90051c6b5440c7e574d1896f8037e3c96cf17aaeb054c9311cfbf4d" url: "https://pub.dev" source: hosted - version: "2.4.12" + version: "2.4.13" build_runner_core: dependency: transitive description: diff --git a/app/pubspec.yaml b/app/pubspec.yaml index d047563c..a7b8779f 100644 --- a/app/pubspec.yaml +++ b/app/pubspec.yaml @@ -50,7 +50,7 @@ dependencies: dev_dependencies: auto_route_generator: ^7.3.2 bloc_test: ^9.0.3 - build_runner: ^2.1.11 + build_runner: ^2.4.13 flutter_launcher_icons: ^0.13.1 flutter_lints: ^3.0.1 flutter_test: