generateReport method

Future<String> generateReport()

Implementation

Future<String> generateReport() async {
  String text = 'Failure Report:\n';
  final dateTime = DateTime.fromMillisecondsSinceEpoch(int.parse(id) * 1000);

  text += 'DateTime: $dateTime\n';
  text += 'ID: $id\n';
  text += 'Type: $type\n';
  //Exception
  if (failureInfo.exception != null) {
    text += 'Exception: ${failureInfo.exception}\n';
  }
  if (failureInfo.request != null) {
    text += '\nRequest:\n';
    text += 'URL: ${failureInfo.request!.uri}\n';
    text += 'Method: ${failureInfo.request!.method}\n';
    //Query Parameters
    // text += 'Query Parameters:\n';
    // text += '${await failureInfo.request!}\n';

    //Data
    // final data = await failureInfo.request!.data;
    // if (data != null) {
    //   text += 'Data:\n';
    //   text += '${await failureInfo.request!.data}\n';
    // }
    if (failureInfo.response?.requestOptions == null) {
      //headers
      text += 'Request Headers:\n';
      text += '${failureInfo.request!.headers}\n';
      //curl
      final curl = await request2curl(failureInfo.request);
      if (curl != null) {
        text += '\nStart Curl:\n\n';
        text += '$curl\n';
        text += '\nEnd Curl\n\n';
      }
    }
  }
  text += '\n';
  if (failureInfo.response != null) {
    text += 'Request Headers:\n';
    text += '${failureInfo.response?.requestOptions.headers}\n';
    final curl = dio2curl(failureInfo.response?.requestOptions);
    if (curl != null) {
      text += '\nStart Curl:\n\n';
      text += '$curl\n';
      text += 'End Curl\n\n';
    }
    text += 'Response:\n';
    text += 'Status: ${failureInfo.response?.statusCode}\n';
    text += 'Response Headers:\n';
    text += '${failureInfo.response?.headers}\n';
    text += 'Data:\n';
    text += '${failureInfo.response?.data}\n';
  }
  text += '\n';
  text = text.replaceAll('{', '{\n');
  text = text.replaceAll(',', ',\n');
  text = text.replaceAll('}', '\n}');

  return base64.encode(utf8.encode(text));
}