Closed LeXuanKhanh closed 4 days ago
Based on the answers on the issue you linked, this is how I managed to print curl request onError. You can do the same with other interceptors:
String cURLRepresentation(RequestOptions options) {
List<String> components = ['\$ curl -i'];
if (options.method.toUpperCase() == 'GET') {
components.add('-X ${options.method}');
}
options.headers.forEach((k, v) {
if (k != 'Cookie') {
components.add('-H \"$k: $v\"');
}
});
var data = json.encode(options.data);
data = data.replaceAll('\"', '\\\"');
components.add('-d \"$data\"');
components.add('\"${options.uri.toString()}\"');
return components.join('\\\n\t');
}
_dio.interceptors.add(InterceptorsWrapper(onError: (DioError e, handler) {
// add a breakpoint here so all errors can break
try {
print(cURLRepresentation(e.requestOptions));
} catch (err) {
print('unable to create a CURL representation of the errored');
}
return handler.next(e); //continue
}));
not in the scope of this lib
Hi, the answer in https://github.com/flutterchina/dio/issues/687 have no longer work, can you add the options which will log the additional curl of the request ?