You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
HttpRequest.getString() throws ProgressEvent instead of Error or Exception (dart:html) #60239
Handling HttpRequest.getString() on a non-existent URL with try/catch or then/catchError.
Expected results:
Will return the Error or Exception if there's an error with the URL or the file is not found.
Actual results:
Returns an instance of ProgressEvent instead of Error or Exception.
Workaround
I could check if the error is an instance of ProgressEvent, and then read the currentTarget (reference to a XmlHttpRequest instance) and then the responseText or statusText or status properties to retrieve the status code, but is not intuitive or practical. Only Errors or Exception should be thrown, not instances of Event or other classes. Am I missing something?
Logs
Reacted by Stefanos Grammenos, weiqingtangx, Thomas Verbeek and Josue
changed the title [-][BUG or FEATURE?] HttpRequest.getString() throws ProgressEvent instead of Error or Exception (dart:html)[/-][+]HttpRequest.getString() throws ProgressEvent instead of Error or Exception (dart:html)[/+]on Jun 25, 2020
nstance of '_Future<String>'
Error: [object ProgressEvent]
at Object.createErrorWithStack (http://localhost:54526/dart_sdk.js:4479:12)
at Object._rethrow (http://localhost:54526/dart_sdk.js:37395:16)
at async._AsyncCallbackEntry.new.callback (http://localhost:54526/dart_sdk.js:37389:13)
at Object._microtaskLoop (http://localhost:54526/dart_sdk.js:37221:13)
at _startMicrotaskLoop (http://localhost:54526/dart_sdk.js:37227:13)
at http://localhost:54526/dart_sdk.js:32849:9
This problem still appears in Flutter 3.0.1. It would be interesting to know, if it is a situation which has to be accepted and work-arounded or whether a fix can be expected in the near future? Is this a Flutter bug, a dart bug or a browser bug?
For anyone who is interested, my workaround for this bug looks like this:
boolisNetworkImageUnauthorizedError(dynamic error) {
if (error isNetworkImageLoadException&& error.statusCode ==401) {
returntrue;
}
//Because of this bug, we need to analyze the error for ProgressEvent//https://github.com/flutter/flutter/issues/44370//https://github.com/flutter/flutter/issues/60239if(error is html.ProgressEvent&& error.currentTarget !=null) {
if (error.currentTarget is html.HttpRequest) {
html.HttpRequest request = error.currentTarget as html.HttpRequest;
if (request.status ==401) {
returntrue;
}
}
}
returnfalse;
}
Launching lib/main.dart on Chrome in debug mode...This app is linked to the debug service: ws://127.0.0.1:51204/CSTORrGFaBY=/wsDebug service listening on ws://127.0.0.1:51204/CSTORrGFaBY=/ws💪 Running with sound null safety 💪Connecting to VM Service at ws://127.0.0.1:51204/CSTORrGFaBY=/ws<!DOCTYPE html><html><head> <!-- If you are serving your web app in a path other than the root, change the href value below to reflect the base path you are serving from. The path provided below has to start and end with a slash "/" in order for it to work correctly. For more details: * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base This is a placeholder for base href that will be replaced by the value of the `--base-href` argument provided to `flutter build`. --> <base href="/"> <meta charset="UTF-8"> <meta content="IE=Edge" http-equiv="X-UA-Compatible"> <meta name="description" content="A new Flutter project."> <!-- iOS meta tags & icons --> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-status-bar-style" content="black"> <meta name="apple-mobile-web-app-title" content="flutter_issue"> <link rel="apple-touch-icon" href="icons/Icon-192.png"> <!-- Favicon --> <link rel="icon" type="image/png" href="favicon.png"/> <title>flutter_issue</title> <link rel="manifest" href="manifest.json"> <script> // The value below is injected by flutter build, do not touch. var serviceWorkerVersion = null; </script> <!-- This script adds the flutter initialization JS code --> <script src="flutter.js" defer></script></head><body> <script> window.addEventListener('load', function(ev) {// Download main.dart.js _flutter.loader.loadEntrypoint({ serviceWorker: { serviceWorkerVersion: serviceWorkerVersion, }, onEntrypointLoaded: function(engineInitializer) { engineInitializer.initializeEngine().then(function(appRunner) { appRunner.runApp(); }); } }); }); </script></body></html>
flutter doctor -v (mac)
[✓] Flutter (Channel master, 3.7.0-13.0.pre.131, on macOS 13.1 22C65 darwin-arm64, locale en-IN)
• Flutter version 3.7.0-13.0.pre.131 on channel master at /Users/mahesh/Development/flutter_master
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 0196e6050b (2 days ago), 2022-12-31 11:10:23 -0500
• Engine revision 932591ec04
• Dart version 3.0.0 (build 3.0.0-76.0.dev)
• DevTools version 2.20.0
• If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks
and upgrades.
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc4)
• Android SDK at /Users/mahesh/Library/Android/sdk
• Platform android-33, build-tools 33.0.0-rc4
• ANDROID_HOME = /Users/mahesh/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 14A400
• CocoaPods version 1.11.3
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2021.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
[✓] IntelliJ IDEA Community Edition (version 2021.2.1)
• IntelliJ at /Applications/IntelliJ IDEA CE.app
• Flutter plugin version 61.2.4
• Dart plugin version 212.5080.8
[✓] VS Code (version 1.74.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.56.0
[✓] Connected device (3 available)
• iPhone 12 Pro (mobile) • 026D5789-9E78-4AD5-B1B2-3F8D4E7F65E4 • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-5 (simulator)
• macOS (desktop) • macos • darwin-arm64 • macOS 13.1 22C65 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 108.0.5359.124
[✓] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!
[✓] Flutter (Channel stable, 3.3.9, on macOS 12.6 21G115 darwin-arm, locale en-IN)
• Flutter version 3.3.9 on channel stable at /Users/mahesh/Development/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision b8f7f1f986 (24 hours ago), 2022-11-23 06:43:51 +0900
• Engine revision 8f2221fbef
• Dart version 2.18.5
• DevTools version 2.15.0
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc4)
• Android SDK at /Users/mahesh/Library/Android/sdk
• Platform android-33, build-tools 33.0.0-rc4
• ANDROID_HOME = /Users/mahesh/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 14A400
• CocoaPods version 1.11.3
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2021.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
[✓] IntelliJ IDEA Community Edition (version 2021.2.1)
• IntelliJ at /Applications/IntelliJ IDEA CE.app
• Flutter plugin version 61.2.4
• Dart plugin version 212.5080.8
[✓] VS Code (version 1.70.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.53.20221101
[✓] Connected device (3 available)
• iPhone 12 Pro (mobile) • 026D5789-9E78-4AD5-B1B2-3F8D4E7F65E4 • ios •
com.apple.CoreSimulator.SimRuntime.iOS-14-5 (simulator)
• macOS (desktop) • macos • darwin-arm64 • macOS 12.6 21G115 darwin-arm
• Chrome (web) • chrome • web-javascript • Google Chrome 107.0.5304.110
[✓] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!
Activity
[-][BUG or FEATURE?] HttpRequest.getString() throws ProgressEvent instead of Error or Exception (dart:html)[/-][+]HttpRequest.getString() throws ProgressEvent instead of Error or Exception (dart:html)[/+]TahaTesser commentedon Jun 25, 2020
Code Sample
flutter doctor -v
ferhatb commentedon Jan 8, 2021
Note: might be breaking change.
Hixie commentedon Dec 8, 2021
saw this in https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8828452555087042433/+/u/run_test.dart_for_web_long_running_tests_shard_and_subshard_1_5/test_stdout too
technolion commentedon May 24, 2022
This problem still appears in Flutter 3.0.1. It would be interesting to know, if it is a situation which has to be accepted and work-arounded or whether a fix can be expected in the near future? Is this a Flutter bug, a dart bug or a browser bug?
technolion commentedon May 24, 2022
For anyone who is interested, my workaround for this bug looks like this:
maheshj01 commentedon Jan 17, 2023
As of master 3.7 and stable 3.3, there is no error on making a network request for a non existing URL
code sample
logs
flutter doctor -v (mac)
ihsanunot commentedon Jun 1, 2023
I need help, but my english is bad.
so i just want to use Image.network, but always thrown error [object progressevent] :
even in simple code.
i run main.dart with command :
flutter run -d chrome
please somebody help me thanks :)
``