Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/curl_logger_dio_interceptor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import 'package:dio/dio.dart';
class CurlLoggerDioInterceptor extends Interceptor {
final bool? printOnSuccess;
final bool convertFormData;
final void Function(String msg)? logFunction;

CurlLoggerDioInterceptor({this.printOnSuccess, this.convertFormData = true});
CurlLoggerDioInterceptor(
{this.logFunction, this.printOnSuccess, this.convertFormData = true});

@override
void onError(DioError err, ErrorInterceptorHandler handler) {
Expand All @@ -31,7 +33,12 @@ class CurlLoggerDioInterceptor extends Interceptor {
void _renderCurlRepresentation(RequestOptions requestOptions) {
// add a breakpoint here so all errors can break
try {
log(_cURLRepresentation(requestOptions));
var msg = _cURLRepresentation(requestOptions);
if (logFunction != null) {
logFunction!(msg);
} else {
log(msg);
}
} catch (err) {
log('unable to create a CURL representation of the requestOptions');
}
Expand Down