-
Notifications
You must be signed in to change notification settings - Fork 26.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HttpRequest.getString() throws ProgressEvent instead of Error or Exception (dart:html) #60239
Comments
Code Sample
flutter doctor -v
|
Note: might be breaking change. |
This does three things: * Add more asserts around the devtools launching * Add more defensive checks around the devtools launching in case we're seeing shutdown races * Enable the asserts for the web tests. The idea is to either avoid a flake like this, or make the logs more useful: 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 See also flutter#60239
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: bool isNetworkImageUnauthorizedError(dynamic error) {
if (error is NetworkImageLoadException && error.statusCode == 401) {
return true;
}
//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/60239
if(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) {
return true;
}
}
}
return false;
} |
As of master 3.7 and stable 3.3, there is no error on making a network request for a non existing URL code sampleimport 'dart:html';
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Material App',
theme: ThemeData.dark(),
home: const Home(),
);
}
}
class Home extends StatelessWidget {
const Home({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Material App Bar'),
),
body: const Center(
child: Text('Hello World'),
),
floatingActionButton: FloatingActionButton(
child: const Icon(Icons.add),
onPressed: () async {
final test = await HttpRequest.getString('url');
print(test);
},
),
);
}
}
logsLaunching lib/main.dart on Chrome in debug mode...
This app is linked to the debug service: ws://127.0.0.1:51204/CSTORrGFaBY=/ws
Debug 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)
|
I need help, but my english is bad. so i just want to use Image.network, but always thrown error [object progressevent] : i run main.dart with command :
please somebody help me thanks :) `` |
dart:html
Steps to Reproduce
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
The text was updated successfully, but these errors were encountered: