onError method
The callback will be executed on error.
If you want to continue the error , call handler.next.
If you want to complete the response with some custom data directly,
you can resolve a Response object with handler.resolve and other
error interceptor(s) will be skipped.
If you want to complete the response with an error message directly,
you can reject a DioError object with handler.reject, and other
error interceptor(s) will be skipped.
Implementation
@override
void onError(DioError err, ErrorInterceptorHandler handler) async {
var box = await getBox<CallCacheModel>('calls');
var model = box.get(box.values.toList().length);
if (model != null) {
var type = err.type;
await box.put(
box.values.toList().length,
model.copyWith(
eventMessage: err.stackTrace.toString(),
statusCode: type == DioErrorType.other
? "-1"
: err.response?.statusCode.toString(),
response: err.response?.data.toString()));
}
super.onError(err, handler);
}