Comments (5)
@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.
Please attach more precise details so we can take further investigations. Thanks.
from dio.
Related Issues (20)
- Running Gradle task 'assembleProfile'.. ../../../.pub-cache/hosted/pub.dev/dio-5.4.3/lib/src/ form_data.dart:175:54: Error: The argument type 'List <int>' can't be assigned to the parameter type 'Uint8list'. HOT 1
- Improve Exception Detailing for Dio HOT 1
- Improve Exception Detailing for Dio Package HOT 1
- SocketException: Connection reset by peer (OS Error: Connection reset by peer, errno = 104), address = XXXX, port = 49440 HOT 2
- Docs for merging between `Options` and `BaseOptions` are not clear HOT 12
- Cookie manager path match error HOT 1
- When using Dio in a web environment, there needs to be a way to disable Dioβs automatic cookie setting HOT 8
- Prompt for not simple requests on Web HOT 2
- DioException response.data is null HOT 1
- [native_dio_adapter] Windows build breaks when adding package HOT 1
- DioException (DioException [connection error]: The connection errored: Connection reset by peer This indicates an error which most likely cannot be solved by the library. HOT 3
- Add privacy manifest file for iOS HOT 1
- incorrect formatting when parsing `multipart` form data using `FormData.fromMap()` causes `NullReferenceException` in .NET backend HOT 2
- I can't return my own errors class in onError interceptor HOT 1
- RFC - Custom DNS Resolver HOT 2
- I can't use MediaType when I create MultipartFile HOT 1
- Update for wasm HOT 1
- Implement automatic redirects for requests regardless of the `HttpClient` HOT 1
- Migrating browser_adapter.dart for WASM HOT 2
- Remove the message 'The request was manually cancelled by the user.' for canceltoken.cancel() HOT 1
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.