Skip to content

Commit

Permalink
refactor(#660): response error handling in parent lab class
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Nov 13, 2024
1 parent 5966e70 commit 648c4a0
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 18 deletions.
6 changes: 3 additions & 3 deletions app/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down Expand Up @@ -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 = (
Expand Down Expand Up @@ -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 = (
Expand Down
12 changes: 9 additions & 3 deletions app/lib/login/models/lab.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:convert';

import 'package:http/http.dart';
import 'package:http/http.dart' as http;

import '../../common/module.dart';

Expand All @@ -24,11 +24,17 @@ class Lab {
throw UnimplementedError();
}

(List<LabResult>, List<String>) labDataFromHTTPResponse(Response response) {
Future<(List<LabResult>, List<String>)> fetchData(
Uri dataUrl,
{
Map<String,String>? headers,
}) async {
final response = await http.get(dataUrl, headers: headers);
if (response.statusCode != 200) throw Exception();
final json = jsonDecode(response.body) as Map<String, dynamic>;
final labData = json['diplotypes'].map<LabResult>(
LabResult.fromJson
).toList();
).toList() as List<LabResult>;
var activeDrugs = <String>[];
if (json.containsKey('medications')) {
activeDrugs = List<String>.from(json['medications']);
Expand Down
10 changes: 1 addition & 9 deletions app/lib/login/models/oauth_authorization_code_flow_lab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,6 @@ class OAuthAuthorizationCodeFlowLab extends Lab {

@override
Future<(List<LabResult>, List<String>)> 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'});
}
}
4 changes: 2 additions & 2 deletions app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 648c4a0

Please sign in to comment.