getR3Data function
Future
getR3Data(
- dynamic guid,
- dynamic params, {
- dynamic isReLogin = false,
})
Implementation
Future<dynamic> getR3Data(guid, params, {isReLogin = false}) async {
params ??= [
{"Name": "", "Value": ""}
];
try {
String url = '${DB.dbR3Url}$r3UrlGetCustomQData${DB.dbR3MS}?GUID=$guid';
//debugPrint('URL $url');
dynamic response = await dio.post(url, data: params);
//log('getR3Data Session => ${dio.options.headers.keys.}');
dynamic d;
if (response.statusCode == 200) {
try {
d = response.data;
if (d["status"] == 200) {
if (d["data"] != "") {
return {'status': 200, 'data': jsonDecode(d["data"]), 'message': ''};
} else {
return {'status': 404, 'data': '', 'message': 'No data found'};
}
} else {
//Try re login if the session is expired and call the getR3Data() for one more time
if (!isReLogin) {
bool isValidMS = await isValidR3Session();
if (!isValidMS) {
dynamic d = await r3Login(DB.dbUserName, DB.dbPassword, DB.dbCompanyGUID);
if (d["Status"] == 200) {
return await getR3Data(guid, params, isReLogin: true);
}
}
}
return {'status': 404, 'data': '', 'message': 'getR3Data()->api call failed on GUID:($guid) ${d["error"]}'};
}
} catch (e) {
throw ("Unable to decode the response. $e");
}
} else {
return {'status': 404, 'data': '', 'message': 'getR3Data()->api call failed.${response.statusMessage}'};
}
} catch (e) {
return {'status': 404, 'data': '', 'message': 'getR3Data()->api call failed. GUID:$guid Params:${jsonEncode(params)}. $e'};
}
}