httpPostResponse method
Implementation
Future<dynamic> httpPostResponse(
{required String uri, Object? body, Map<String, String>? headers}) async {
try {
final http.Response response = await http.post(
Uri.parse('$baseUrl/$uri'),
body: body,
headers: headers,
);
if (response.statusCode == 200 || response.statusCode == 201) {
return json.decode(response.body);
}
throw ApiException(
statusCode: response.statusCode,
message: 'Error to load REST API data: ${response.reasonPhrase}');
} on TimeoutException catch (e) {
throw ApiException(message: 'Error connection timeout: ${e.message}');
} on SocketException catch (e) {
throw ApiException(message: 'Socket error: ${e.message}');
} on Error catch (e) {
throw ApiException(message: 'General error: $e');
}
}