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) async {
  /// If unauthorized (401), call the onUnauthorized callback and remove token.
  if (err.response?.statusCode == 401 && onUnauthorized != null) {
    onUnauthorized!();
    await LocalStorageService.removeToken();
  }

  /// Forward the error.
  handler.next(err);
}