dio icon indicating copy to clipboard operation
dio copied to clipboard

Unable to catch assureDioError using try-catch

Open DenzelCode opened this issue 5 years ago • 14 comments

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.

image

image

image

DenzelCode avatar Jul 19 '21 20:07 DenzelCode

Same happening with me.

dhsont avatar Jul 21 '21 18:07 dhsont

+1 execution never reaches the catch block.

sysquo-aditya avatar Jul 24 '21 06:07 sysquo-aditya

+1

Same here.

ghost avatar Jul 26 '21 21:07 ghost

+1

frey-1024 avatar Jul 27 '21 10:07 frey-1024

Hope to solve it quickly, the onError of interceptors will not be triggered

frey-1024 avatar Jul 27 '21 10:07 frey-1024

+1

job-46 avatar Jul 27 '21 14:07 job-46

+1

huanghongxing-jim avatar Jul 27 '21 17:07 huanghongxing-jim

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

Screenshot 2021-07-28 at 10 42 21 AM

Method from where I am calling API.

Screenshot 2021-07-28 at 10 49 52 AM

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.

Screenshot 2021-07-28 at 10 41 31 AM

TheAlphamerc avatar Jul 28 '21 05:07 TheAlphamerc

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.

This work for me, thanks @TheAlphamerc

ghost avatar Jul 28 '21 17:07 ghost

@TheAlphamerc you are my life-saver <3! Works perfectly

novas1r1 avatar Jul 30 '21 06:07 novas1r1

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 avatar Jul 30 '21 06:07 sysquo-aditya

@sysquo-aditya which beta version did you use?

Williano avatar Aug 19 '21 18:08 Williano

in 4.x version, interceptors have changed, the description in changelog:

4.0.0

Interceptors: Add handler for 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.

wendux avatar Oct 23 '21 11:10 wendux

in 4.x version, interceptors have changed, the description in changelog:

4.0.0

Interceptors: Add handler for 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.

2 days ago.... *sniff* mmmmmm, I love the smell of fresh solutions to newest problems

markfili avatar Oct 25 '21 13:10 markfili