07-21-2023, 10:01 PM
I had the same issue, and this is how I solved it.
```
} catch (exception) {
if (exception.runtimeType == DioError) {
var dioException = exception as DioError;
return dioException.response!; // Do something with response
}
rethrow; // or do something else with response
}
}
```
It's similar to some of the answers above, but I had to use `if(exception.runtimeType == DioError)` to check the type of the exception, as `if(exception is DioError)` didn't seem to work for me.
Hope it helps someone.
```
} catch (exception) {
if (exception.runtimeType == DioError) {
var dioException = exception as DioError;
return dioException.response!; // Do something with response
}
rethrow; // or do something else with response
}
}
```
It's similar to some of the answers above, but I had to use `if(exception.runtimeType == DioError)` to check the type of the exception, as `if(exception is DioError)` didn't seem to work for me.
Hope it helps someone.