Comments (4)
@zubair999 try to add super.onError(err, handler)
from dio.
@zubair999 try to add super.onError(err, handler)
I already tried it but it 's not working. I try print in onError code block but request never there, and if reload the app then it print.
from dio.
Your reproducible code is not minimal, which means hard for us to reproduce the case easily. Please consider setting breakpoints and running the app with the debugger to see it it actually works.
from dio.
I have a similar problem. dio version 5.4.1
Expected Behavior:
After the request fails and triggers onError, the retried request within onError should also throw a DioException if it fails, which should then be caught by the try-catch block within the same onError method. This should allow for custom error handling or logging of the retried request failure.
Actual Behavior:
The retried request within onError triggers the onRequest interceptor again as expected, but if the retried request fails, the try-catch block within onError does not catch the subsequent DioException. This behavior prevents custom error handling for the retried request failure from being executed as intended.
Making a GET request...
onRequest is called
onError is called
onRequest is called
import 'package:dio/dio.dart';
class ErrorInterceptor extends QueuedInterceptor {
final Dio dio;
ErrorInterceptor(this.dio);
@override
Future<void> onError(
DioException err, ErrorInterceptorHandler handler) async {
print('onError is called');
try {
// This should throw an error
await dio.fetch(err.requestOptions);
} catch (e) {
// Why cannot I catch the error here?
print('onError is called again');
}
handler.next(err);
}
}
class RequestInterceptor extends Interceptor {
const RequestInterceptor();
@override
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
print('onRequest is called');
return handler.next(options);
}
}
class ResponseIntercepter extends Interceptor {
const ResponseIntercepter();
@override
void onResponse(Response response, ResponseInterceptorHandler handler) {
print('onResponse is called');
handler.next(response);
}
}
void main() async {
var dio = Dio();
// Add the custom interceptor
dio.interceptors.addAll([
const RequestInterceptor(),
const ResponseIntercepter(),
ErrorInterceptor(dio),
]);
// Making a GET request
try {
print('Making a GET request...');
Response response =
await dio.get('https://example.com/this-does-not-exist');
print(response.data);
} catch (e) {
print("Final error: $e");
}
}
from dio.
Related Issues (20)
- How to use handler.reject in onError of QueuedInterceptor HOT 1
- [native_dio_adapter] Exception fetching LoggerImpl class HOT 4
- http请求头不标准,大小写全部错误 HOT 1
- Error using interceptors HOT 1
- [native_dio_adapter] update cronet_http version HOT 1
- Dio REST call response is slow than Postman HOT 5
- Response Header is missing except content-length & content-type HOT 5
- dio https connect can not keep Alive? HOT 8
- 当频繁出现连接和读取异常时,socket句柄无法正常释放 HOT 2
- 当后端返回字节流dio无法解析
- Memory issue when sharing CancelToken between posts for IO implementation HOT 2
- The getter 'requestLock' isn't defined for the type 'Interceptors'. HOT 1
- How can I avoid the cooking value to expanded on each retry? HOT 1
- Cannot add values to dio data inside interceptor HOT 1
- Bad state: Cannot add event after closing HOT 2
- Error: Exception in Java code called through JNI: java.lang.RuntimeException: All available Cronet providers are disabled. A provider should be enabled before it can be used. HOT 1
- socketexception: connection reset by peer (os error: connection reset by peer, errno = 104), address = xxxxx HOT 1
- Dio cannot resolve hostname http://127.0.0.1.lambdatest:port HOT 7
- Unexpected Behavior with ErrorInterceptor Not Catching DioException on Retried Requests HOT 19
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dio.