Skip to content

Commit

Permalink
#131 Handling internal server error response
Browse files Browse the repository at this point in the history
Handling internal server error response when received from Dexcom.
  • Loading branch information
lijogeorgep authored and georgepadayatti committed Oct 20, 2023
1 parent 8945f10 commit 9d7a765
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
10 changes: 9 additions & 1 deletion lib/app/modules/dexcom/controllers/dexcom_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class DexcomController extends BaseController {
startTimer();
}

Future<EstimatedGlucoseValue> getEgvs() async {
Future<EstimatedGlucoseValue?> getEgvs() async {
SharedPreferences _prefs = await SharedPreferences.getInstance();
HttpProvider _httpProvider = HttpProvider();
DateTime now = DateTime.now();
Expand All @@ -172,6 +172,14 @@ class DexcomController extends BaseController {
await refreshToken(); // Refresh the token
continue; // Continue the loop to retry the API call with the new token
}
if (response == '500') {
Get.rawSnackbar(
message: "internal server error",
backgroundColor: Colors.red,
snackPosition: SnackPosition.BOTTOM);

return null;
}

EstimatedGlucoseValue resultedData = EstimatedGlucoseValue.fromJson(response);

Expand Down
3 changes: 3 additions & 0 deletions lib/app/modules/insights/controllers/insights_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ class InsightsController extends BaseController {
}
hideLoading();
}
else{
hideLoading();
}
}
else{
hideLoading();
Expand Down
8 changes: 7 additions & 1 deletion lib/app/network/http_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import '../../flavors/build_config.dart';

const int statusCodeValue = 200;
const int invalidAccessToken = 401;
const int internalServerError=500;

class HttpProvider {
static final String? baseUrl = BuildConfig.instance.config.dexComBaseUrl;
Expand Down Expand Up @@ -51,7 +52,12 @@ class HttpProvider {
} else if (response.statusCode == invalidAccessToken) {

return '401';
} else {
}
else if (response.statusCode==internalServerError){

return '500';
}
else {
throw Exception('Failed to retrieve glucose values.');
}
}
Expand Down

0 comments on commit 9d7a765

Please sign in to comment.