postToChatGpt method
Implementation
Future<dynamic> postToChatGpt(RequestHttp requestHttp, Map<String, dynamic> requestBody) async {
log("$_tag requestHttp = ${requestHttp.toString()}");
Response response;
try {
if (requestHttp.headers!.isEmpty) {
response = await post(Uri.parse(requestHttp.toUrl()),
body: jsonEncode(requestBody),
headers: {'Content-Type': 'application/json'});
} else {
response = await post(Uri.parse(requestHttp.toUrl()),
body: jsonEncode(requestBody),
headers: {
...?requestHttp.headers,
'Content-Type': 'application/json',
});
}
if (response.statusCode != 200) {
print('Error: ${response.body}');
throw Exception('Error: Something goes badly getting the info of the service. statusCode= ${response.statusCode}');
}
return ResponseHttp(response).getResponseMapHttp();
} catch (e) {
print('Error: ${e.toString()}');
throw Exception('Error: Something goes badly getting the info of the service. error= ${e.toString()}');
}
}