diff --git a/lib/client/base_app_client.dart b/lib/client/base_app_client.dart index 9289173c..1066f9d1 100644 --- a/lib/client/base_app_client.dart +++ b/lib/client/base_app_client.dart @@ -130,6 +130,16 @@ class BaseAppClient { if (await Utils.checkConnection()) { final response = await http.post(Uri.parse(url), body: json.encode(body), headers: {'Content-Type': 'application/json', 'Accept': 'application/json'}); final int statusCode = response.statusCode; + + if (body['DoctorID'] != null) { + postRequestAndResponse( + doctorId: body['DoctorID'], + completeUrl: url, + request: json.encode(body), + response: response.body, + urlSuffix: endPoint, + statusCode: statusCode.toString()); + } if (statusCode < 200 || statusCode >= 400) { onFailure(Utils.generateContactAdminMsg(), statusCode); if (body['DoctorID'] != null) postFailureResponse(doctorId: body['DoctorID'], url: url, request: json.encode(body), response: response.body, exception: "$statusCode"); diff --git a/lib/utils/exception_report.dart b/lib/utils/exception_report.dart index 2e039703..a83013fe 100644 --- a/lib/utils/exception_report.dart +++ b/lib/utils/exception_report.dart @@ -1,4 +1,23 @@ -// import 'package:cloud_firestore/cloud_firestore.dart'; + +import 'package:cloud_firestore/cloud_firestore.dart'; + +List monitoredEndpoints = [ + "Services/Sentry.svc/REST/MemberLogIN_New", + 'Services/DoctorApplication.svc/REST/GetProjectInfo', + 'Services/DoctorApplication.svc/REST/DoctorApp_GetDeviceDetailsByIMEI', + 'Services/DoctorApplication.svc/REST/SendActivationCodeForDoctorApp', + 'Services/DoctorApplication.svc/REST/CheckActivationCodeForDoctorApp', + 'Services/Doctors.svc/REST/GetDocProfiles', + 'Services/DoctorApplication.svc/REST/DoctorApp_GetDoctorNotRepliedCounts', + 'Services/DoctorApplication.svc/REST/GetClinicsForDoctor', + 'Services/DoctorApplication.svc/REST/GetDoctorDashboardKPI', + 'Services/DoctorApplication.svc/REST/GetSpecialClinicalCareList', + 'Services/DoctorApplication.svc/REST/IsInfectiousDiseasesConsultant', + 'Services/DoctorApplication.svc/REST/IsInterventionAccessLevel3Pending', + 'Services/DoctorApplication.svc/REST/CheckDoctorHasLiveCare', + 'Services/DoctorApplication.svc/REST/FetchRadCriticalFinding', + 'Services/DoctorApplication.svc/REST/DoctorApp_InsertOrUpdateDeviceDetails' +]; void postFailureResponse({ required dynamic doctorId, @@ -16,4 +35,32 @@ void postFailureResponse({ // final firestore = FirebaseFirestore.instance; // final collectionRef = firestore.collection(doctorId.toString()); // await collectionRef.doc(DateTime.now().toIso8601String()).set(data); +} + + +void postRequestAndResponse({ + required dynamic doctorId, + required String completeUrl, + required String urlSuffix, + required String request, + required String response, + required String statusCode, +}) async { + if(!monitoredEndpoints.contains(urlSuffix)) { + return; + } + print(" the url is being logged "); + Map data = { + "url" : completeUrl, + "request" : request, + "response" : response, + "statusCode" : statusCode, + }; + final firestore = FirebaseFirestore.instance; + // Sanitize urlSuffix to be Firestore-safe + final safeSuffix = urlSuffix.replaceAll(RegExp(r'[^a-zA-Z0-9_-]'), '_'); + final collectionRef = firestore.collection('doctors') + .doc(doctorId.toString()) + .collection(safeSuffix); + await collectionRef.doc(DateTime.now().toIso8601String()).set(data); } \ No newline at end of file