dispatch method Null safety

  1. @override
Future<bool> dispatch(
  1. String json
)
override

Sends the given json to the backend.

Implementation

@override
Future<bool> dispatch(String json) async {
  if (_ingestToken.isEmpty == true) throw 'Humio ingest token is not defined';
  if (ingestUrl.isEmpty == true) throw 'Humio ingest URL is not defined';

  var dio = Dio();

  Response<dynamic> response;
  try {
    response = await dio.post(
      ingestUrl,
      data: json,
      options: Options(
        contentType: 'application/json',
        headers: {'Authorization': 'Bearer $_ingestToken'},
      ),
    );
  } on DioError catch (e) {
    print('Humio log error: ${e.message}');

    return false;
  }

  return response.statusCode == 200;
}