onError method

  1. @override
void onError(
  1. DioException err,
  2. ErrorInterceptorHandler handler
)

Called when an exception was occurred during the request.

Implementation

@override
void onError(DioException err, ErrorInterceptorHandler handler) {
  final String? id = err.requestOptions.extra[kDsiRequestIdExtraKey] as String?;
  if (id != null && err.response != null) {
    final CurlModel? curlModel = CurlLogs.instance.getById(id);
    if (curlModel != null) {
      try {
        final CurlModel updatedCurlModel = curlModel.copyWith(
          status: err.response?.statusCode,
          response: err.response?.data,
          responseSize: Utils.estimateSize(err.response?.data),
        );
        CurlLogs.instance.replace(replace: curlModel, save: updatedCurlModel);
      } catch (e) {
        debugPrint('DioshakerInterceptor error: $e');
      }
    }
  }
  super.onError(err, handler);
}