import 'dart:developer';
import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';

class LoggingInterceptor extends Interceptor {
  @override
  void onResponse(
    Response<dynamic> response,
    ResponseInterceptorHandler handler,
  ) {
    if (!kReleaseMode) {
      log(
        'RESPONSE ${response.statusCode}\n${response.requestOptions.uri}\n${response.data}',
        name: 'DIO_RESPONSE',
      );
    }
    handler.next(response);
  }

  @override
  void onError(
    DioException err,
    ErrorInterceptorHandler handler,
  ) {
    if (!kReleaseMode) {
      log(
        'ERROR ${err.response?.statusCode}\n'
        '${err.requestOptions.uri}\n'
        '${err.type}\n'
        '${err.response?.data}',
        name: 'DIO_ERROR',
      );
    }
    handler.next(err);
  }
}
