printHttpResponse function

void printHttpResponse({
  1. required String method,
  2. required String url,
  3. required int statusCode,
  4. bool? success,
  5. Object? body,
  6. Duration? duration,
  7. String? tag = 'HTTP',
})

Logs an HTTP response summary.

Implementation

void printHttpResponse({
  required String method,
  required String url,
  required int statusCode,
  bool? success,
  Object? body,
  Duration? duration,
  String? tag = 'HTTP',
}) {
  final ok = success ?? (statusCode >= 200 && statusCode < 300);
  final level = ok ? PrintfLevel.success : PrintfLevel.error;
  final statusIcon = ok ? '✅' : '❌';
  printf(
    [
      printfSeparator(object: '$method RESPONSE', length: 14),
      '$statusIcon $statusCode  $url',
      if (duration != null) 'TIME : ${duration.inMilliseconds}ms',
      if (body != null) 'BODY : ${_formatPayload(body)}',
      printfSeparator(length: 40),
    ].join('\n'),
    tag: tag,
    level: level,
    style: PrintfStyle.network,
    timestamp: true,
  );
}