|
|
|
|
@ -1,12 +1,14 @@
|
|
|
|
|
import 'dart:async';
|
|
|
|
|
import 'dart:convert';
|
|
|
|
|
import 'dart:developer';
|
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/core/api_consts.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/core/app_state.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/core/dependencies.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/core/utils/utils.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/generated/locale_keys.g.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/presentation/home/app_update_page.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/routes/app_routes.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/services/analytics/analytics_service.dart';
|
|
|
|
|
@ -172,8 +174,9 @@ class ApiClientImp implements ApiClient {
|
|
|
|
|
// body['VersionID'] = ApiConsts.appVersionID.toString();
|
|
|
|
|
if (!isExternal) {
|
|
|
|
|
body['VersionID'] = ApiConsts.appVersionID.toString();
|
|
|
|
|
if(!isRCService)
|
|
|
|
|
body['Channel'] = ApiConsts.appChannelId.toString();
|
|
|
|
|
if (!isRCService) {
|
|
|
|
|
body['Channel'] = ApiConsts.appChannelId.toString();
|
|
|
|
|
}
|
|
|
|
|
body['IPAdress'] = ApiConsts.appIpAddress;
|
|
|
|
|
body['generalid'] = ApiConsts.appGeneralId;
|
|
|
|
|
|
|
|
|
|
@ -224,9 +227,9 @@ class ApiClientImp implements ApiClient {
|
|
|
|
|
|
|
|
|
|
if (!networkStatus) {
|
|
|
|
|
onFailure(
|
|
|
|
|
'Please Check The Internet Connection 1',
|
|
|
|
|
LocaleKeys.networkPleaseCheckInternet.tr(),
|
|
|
|
|
-1,
|
|
|
|
|
failureType: ConnectivityFailure("Please Check The Internet Connection 1"),
|
|
|
|
|
failureType: ConnectivityFailure(LocaleKeys.networkPleaseCheckInternet.tr()),
|
|
|
|
|
);
|
|
|
|
|
_analytics.errorTracking.log("internet_connectivity", error: "no internet available");
|
|
|
|
|
return;
|
|
|
|
|
@ -237,12 +240,37 @@ class ApiClientImp implements ApiClient {
|
|
|
|
|
debugPrint("uri: ${Uri.parse(url.trim())}");
|
|
|
|
|
var requestBodyJSON = json.encode(body);
|
|
|
|
|
debugPrint("body: $requestBodyJSON", wrapWidth: 2048);
|
|
|
|
|
final response = await http.post(Uri.parse(url.trim()), body: requestBody, headers: headers);
|
|
|
|
|
|
|
|
|
|
http.Response response;
|
|
|
|
|
try {
|
|
|
|
|
response = await http.post(Uri.parse(url.trim()), body: requestBody, headers: headers);
|
|
|
|
|
} on SocketException catch (e) {
|
|
|
|
|
final message = e.message.contains('Connection reset by peer') ? LocaleKeys.networkConnectionReset.tr() : LocaleKeys.networkErrorMessage.tr();
|
|
|
|
|
onFailure(message, -1, failureType: ConnectivityFailure(message));
|
|
|
|
|
_analytics.errorTracking.log(endPoint, error: "SocketException: $e");
|
|
|
|
|
return;
|
|
|
|
|
} on http.ClientException catch (e) {
|
|
|
|
|
final message = e.message.contains('Connection reset by peer') ? LocaleKeys.networkConnectionReset.tr() : LocaleKeys.networkErrorMessage.tr();
|
|
|
|
|
onFailure(message, -1, failureType: ConnectivityFailure(message));
|
|
|
|
|
_analytics.errorTracking.log(endPoint, error: "ClientException: $e");
|
|
|
|
|
return;
|
|
|
|
|
} on TimeoutException catch (_) {
|
|
|
|
|
final message = LocaleKeys.networkTimeout.tr();
|
|
|
|
|
onFailure(message, -1, failureType: ConnectivityFailure(message));
|
|
|
|
|
_analytics.errorTracking.log(endPoint, error: "TimeoutException");
|
|
|
|
|
return;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
final message = LocaleKeys.networkUnknownError.tr();
|
|
|
|
|
onFailure(message, -1, failureType: ConnectivityFailure(message));
|
|
|
|
|
_analytics.errorTracking.log(endPoint, error: "UnknownException: $e");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final int statusCode = response.statusCode;
|
|
|
|
|
// log("response.body: ${response.body}");
|
|
|
|
|
if (statusCode < 200 || statusCode >= 400) {
|
|
|
|
|
onFailure('Error While Fetching data', statusCode, failureType: StatusCodeFailure("Error While Fetching data"));
|
|
|
|
|
logApiEndpointError(endPoint, 'Error While Fetching data', statusCode);
|
|
|
|
|
onFailure(LocaleKeys.networkErrorWhileFetching.tr(), statusCode, failureType: StatusCodeFailure(LocaleKeys.networkErrorWhileFetching.tr()));
|
|
|
|
|
logApiEndpointError(endPoint, LocaleKeys.networkErrorWhileFetching.tr(), statusCode);
|
|
|
|
|
} else {
|
|
|
|
|
var parsed = json.decode(utf8.decode(response.bodyBytes));
|
|
|
|
|
if (isAllowAny) {
|
|
|
|
|
@ -277,7 +305,8 @@ class ApiClientImp implements ApiClient {
|
|
|
|
|
onFailure(
|
|
|
|
|
parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'],
|
|
|
|
|
statusCode,
|
|
|
|
|
failureType: UnAuthenticatedUserFailure(parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'] ?? "User is not Authenticated", url: url),
|
|
|
|
|
failureType:
|
|
|
|
|
UnAuthenticatedUserFailure(parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'] ?? "User is not Authenticated", url: url),
|
|
|
|
|
);
|
|
|
|
|
// logApiEndpointError(endPoint, "session logged out", statusCode);
|
|
|
|
|
}
|
|
|
|
|
@ -322,16 +351,16 @@ class ApiClientImp implements ApiClient {
|
|
|
|
|
if (parsed['message'] == null && parsed['ErrorEndUserMessage'] == null) {
|
|
|
|
|
if (parsed['ErrorSearchMsg'] == null) {
|
|
|
|
|
onFailure(
|
|
|
|
|
"Server Error found with no available message",
|
|
|
|
|
LocaleKeys.networkServerErrorNoMessage.tr(),
|
|
|
|
|
statusCode,
|
|
|
|
|
failureType: ServerFailure("Error While Fetching data"),
|
|
|
|
|
failureType: ServerFailure(LocaleKeys.networkErrorWhileFetching.tr()),
|
|
|
|
|
);
|
|
|
|
|
logApiEndpointError(endPoint, "Server Error found with no available message", statusCode);
|
|
|
|
|
logApiEndpointError(endPoint, LocaleKeys.networkServerErrorNoMessage.tr(), statusCode);
|
|
|
|
|
} else {
|
|
|
|
|
onFailure(
|
|
|
|
|
parsed['ErrorSearchMsg'],
|
|
|
|
|
statusCode,
|
|
|
|
|
failureType: ServerFailure("Error While Fetching data"),
|
|
|
|
|
failureType: ServerFailure(LocaleKeys.networkErrorWhileFetching.tr()),
|
|
|
|
|
);
|
|
|
|
|
logApiEndpointError(endPoint, parsed['ErrorSearchMsg'], statusCode);
|
|
|
|
|
}
|
|
|
|
|
@ -353,7 +382,7 @@ class ApiClientImp implements ApiClient {
|
|
|
|
|
onFailure(
|
|
|
|
|
parsed['message'] ?? parsed['message'],
|
|
|
|
|
statusCode,
|
|
|
|
|
failureType: ServerFailure("Error While Fetching data"),
|
|
|
|
|
failureType: ServerFailure(LocaleKeys.networkErrorWhileFetching.tr()),
|
|
|
|
|
);
|
|
|
|
|
logApiEndpointError(endPoint, parsed['message'] ?? parsed['message'], statusCode);
|
|
|
|
|
} else {
|
|
|
|
|
@ -414,22 +443,46 @@ class ApiClientImp implements ApiClient {
|
|
|
|
|
// print("Body : ${json.encode(body)}");
|
|
|
|
|
|
|
|
|
|
if (await Utils.checkConnection(bypassConnectionCheck: true)) {
|
|
|
|
|
final response = await http.get(
|
|
|
|
|
Uri.parse(url.trim()),
|
|
|
|
|
headers: apiHeaders ?? {'Content-Type': 'application/json', 'Accept': 'application/json'},
|
|
|
|
|
);
|
|
|
|
|
http.Response response;
|
|
|
|
|
try {
|
|
|
|
|
response = await http.get(
|
|
|
|
|
Uri.parse(url.trim()),
|
|
|
|
|
headers: apiHeaders ?? {'Content-Type': 'application/json', 'Accept': 'application/json'},
|
|
|
|
|
);
|
|
|
|
|
} on SocketException catch (e) {
|
|
|
|
|
final message = e.message.contains('Connection reset by peer') ? LocaleKeys.networkConnectionReset.tr() : LocaleKeys.networkErrorMessage.tr();
|
|
|
|
|
onFailure(message, -1);
|
|
|
|
|
_analytics.errorTracking.log(endPoint, error: "SocketException: $e");
|
|
|
|
|
return;
|
|
|
|
|
} on http.ClientException catch (e) {
|
|
|
|
|
final message = e.message.contains('Connection reset by peer') ? LocaleKeys.networkConnectionReset.tr() : LocaleKeys.networkErrorMessage.tr();
|
|
|
|
|
onFailure(message, -1);
|
|
|
|
|
_analytics.errorTracking.log(endPoint, error: "ClientException: $e");
|
|
|
|
|
return;
|
|
|
|
|
} on TimeoutException catch (_) {
|
|
|
|
|
final message = LocaleKeys.networkTimeout.tr();
|
|
|
|
|
onFailure(message, -1);
|
|
|
|
|
_analytics.errorTracking.log(endPoint, error: "TimeoutException");
|
|
|
|
|
return;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
final message = LocaleKeys.networkUnknownError.tr();
|
|
|
|
|
onFailure(message, -1);
|
|
|
|
|
_analytics.errorTracking.log(endPoint, error: "UnknownException: $e");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final int statusCode = response.statusCode;
|
|
|
|
|
// print("statusCode :$statusCode");
|
|
|
|
|
|
|
|
|
|
if (statusCode < 200 || statusCode >= 400) {
|
|
|
|
|
onFailure('Error While Fetching data', statusCode);
|
|
|
|
|
logApiEndpointError(endPoint, 'Error While Fetching data', statusCode);
|
|
|
|
|
onFailure(LocaleKeys.networkErrorWhileFetching.tr(), statusCode);
|
|
|
|
|
logApiEndpointError(endPoint, LocaleKeys.networkErrorWhileFetching.tr(), statusCode);
|
|
|
|
|
} else {
|
|
|
|
|
var parsed = json.decode(utf8.decode(response.bodyBytes));
|
|
|
|
|
onSuccess(parsed, statusCode);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
onFailure('Please Check The Internet Connection', -1);
|
|
|
|
|
onFailure(LocaleKeys.networkPleaseCheckInternet.tr(), -1);
|
|
|
|
|
_analytics.errorTracking.log("internet_connectivity", error: "no internet available");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|