request and response are being reported to firestore

update_flutter_3.16.0
Syed Taha Alam 4 months ago
parent f365181888
commit a54ebb91ab

@ -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");

@ -1,4 +1,23 @@
// import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
List<String> 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<String, String> 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);
}
Loading…
Cancel
Save