Unable to catch assureDioError using try-catch
New Issue Checklist
- [] I have searched for a similar issue in the project and found none
Issue Info
| Info | Value | |
|---|---|---|
| Platform Name | e.g. flutter / ios / android | |
| Platform Version | e.g. 1.5.0 / 12.0 / 9.0 | |
| Dio Version | e.g. 2.1.0 / 1.0.17 | |
| Android Studio / Xcode Version | e.g. Android Studio 3.3.2 / Xcode 10.2.1 | |
| Repro rate | e.g. all the time (100%) / sometimes x% / only once | |
| Repro with our demo prj | e.g. does it happen with our demo project? | |
| Demo project link | e.g. link to a demo project that highlights the issue |
Issue Description and Steps
It happens whenever I return a statusCode which refers to an error on my api, I'm not being able to catch the assureDioError which always keep being pointed at on my debug console.



Same happening with me.
+1 execution never reaches the catch block.
+1
Same here.
+1
Hope to solve it quickly, the onError of interceptors will not be triggered
+1
+1
I was facing the same issue but I found out why I wasn't able catch DioError in try-catch block while calling the APi.
For those who are facing the issue, I am posting how It is solved.
Dio client configuration
Method from where I am calling API.
AppInterceptors class
I forgot to call super.onError(dioError, handler); from onError method. After addding this code I was able to catch error in post method shared in above screenshot.
I forgot to call
super.onError(dioError, handler);fromonErrormethod. After addding this code I was able to catch error inpostmethod shared in above screenshot.
This work for me, thanks @TheAlphamerc
@TheAlphamerc you are my life-saver <3! Works perfectly
I have just downgraded to one of the beta versions. No errors so far.
Just seems unnecessary to have to write a new interceptor just to catch errors when previous versions have been doing that already.
@sysquo-aditya which beta version did you use?
in 4.x version, interceptors have changed, the description in changelog:
4.0.0
Interceptors: Add
handlerfor Interceptor APIs which can specify the subsequent interceptors processing logic more finely(whether to skip them or not)).
handler.next : continue to execute the next interceptor
handler.resolve: resolve Response immediately (skip subsequent interceptors )
handler.reject: reject error immediately (skip subsequent interceptors ).
we should call handler API explicitly in Interceptor.
in 4.x version, interceptors have changed, the description in changelog:
4.0.0
Interceptors: Add
handlerfor Interceptor APIs which can specify the subsequent interceptors processing logic more finely(whether to skip them or not)).
handler.next: continue to execute the next interceptorhandler.resolve: resolve Response immediately (skip subsequent interceptors )handler.reject: reject error immediately (skip subsequent interceptors ).we should call
handlerAPI explicitly in Interceptor.
2 days ago.... *sniff* mmmmmm, I love the smell of fresh solutions to newest problems