sendLogs method
Used to send logs to AppCenter server
Implementation
Future<SendLogsResponse> sendLogs(List<Log> logs) async {
_log.fine("Sending logs to AppCenter: logs=$logs");
var listWithMaps = logs.map((e) => e.toMap()).toList();
http.Response response;
try {
var requestBody = jsonEncode({"logs": listWithMaps});
response = await http
.post(_buildUrl(), headers: _buildHeaders(), body: requestBody)
.timeout(_sendTimeout);
} on TimeoutException catch (e, s) {
_log.warning("Timeout at sending logs to AppCenter", e, s);
throw const HttpException(statusCode: 408, message: "Connection timeout");
} catch (e, s) {
_log.severe("Failed to send logs to AppCenter", e, s);
throw HttpException(
statusCode: 500, message: e.toString(), stackTrace: s);
}
var statusCode = response.statusCode;
var responseBody = response.body.toString();
if (statusCode >= 200 && statusCode < 300) {
_log.fine("Response from AppCenter: $responseBody");
return SendLogsResponse.fromMap(json.decode(responseBody));
}
_log.severe(
"Failed to send logs to AppCenter. code=$statusCode", responseBody);
throw HttpException(statusCode: statusCode, message: responseBody);
}