-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
Hi, I am using Dio 5.9.0 in Flutter web (using WASM) with an interceptor to ensure that bearer is added to the header when a 401 occure.
Example code:
@override
Future<void> onError(DioException err, ErrorInterceptorHandler handler) async {
if (err.response?.statusCode == 401) {
_refreshTokenFuture ??= _refreshAccessToken();
final newToken = await _refreshTokenFuture;
_refreshTokenFuture=null;
if (newToken != null) {
// Retry the original request
final clonedRequest = _retryRequest(err.requestOptions, newToken);
try {
final response = await dio.fetch(clonedRequest);
return handler.resolve(response);
} catch (e) {
return handler.next(e as DioException);
}
}
// If refresh fails, newToken == null => pass the 401 up
}
//return handler.next(err);
super.onError(err, handler);
}In the Chrome console I get always first 401 failed (release version):
![]()
Here is a debug view, with all the js-handlers between, dio_mixin.dart line 532 is last call:

Tried a try / catch block around but it still shows the first 401 error.
Chrome error links to this file:
dio/dio/lib/src/dio_mixin.dart
Lines 527 to 537 in 1b6bc25
| Future<Response<dynamic>> _dispatchRequest<T>(RequestOptions reqOpt) async { | |
| final cancelToken = reqOpt.cancelToken; | |
| try { | |
| final stream = await _transformData(reqOpt); | |
| final operation = CancelableOperation.fromFuture( | |
| httpClientAdapter.fetch( | |
| reqOpt, | |
| stream, | |
| cancelToken?.whenCancel, | |
| ), | |
| ); |
httpClientAdapter.fetch() will trigger and then catch block should create exception based on assureDioException() which seems right in the state of DioException() and nothing else.
Will always 4xx errors show when using WASM?
Flutter doctor:
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.38.5, on macOS 26.2 25C56 darwin-arm64, locale nb-NO)
[✓] Android toolchain - develop for Android devices (Android SDK version 36.1.0)
[✓] Xcode - develop for iOS and macOS (Xcode 26.2)
[✓] Chrome - develop for the web
[✓] Connected device (4 available)
[✓] Network resources• No issues found!