Skip to content
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

Open
angelhdzmultimedia opened this issue Jun 24, 2020 · 7 comments
Labels
c: API break Backwards-incompatible API changes dependency: dart Dart team may need to help us found in release: 3.3 Found to occur in 3.3 found in release: 3.7 Found to occur in 3.7 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on P2 Important issues not at the top of the work list platform-web Web applications specifically team-web Owned by Web platform team triaged-web Triaged by Web platform team

Comments

@angelhdzmultimedia
Copy link

angelhdzmultimedia commented Jun 24, 2020

dart:html

Steps to Reproduce

  1. 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
@TahaTesser TahaTesser 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) Jun 25, 2020
@TahaTesser
Copy link
Member

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
Code Sample
import 'dart:html';

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Material App',
      theme: ThemeData.dark(),
      home: Home(),
    );
  }
}

class Home extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Material App Bar'),
      ),
      body: Center(
        child: Container(
          child: Text('Hello World'),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.add),
        onPressed: () {
          final test = HttpRequest.getString('url');
          print(test);
        },
      ),
    );
  }
}

flutter doctor -v
[✓] Flutter (Channel dev, 1.20.0-1.0.pre, on Mac OS X 10.15.5 19F101, locale
    en-GB)
    • Flutter version 1.20.0-1.0.pre at /Users/tahatesser/Code/flutter_dev
    • Framework revision f73f498da1 (7 days ago), 2020-06-18 08:23:22 -0700
    • Engine revision c0d52b98d1
    • Dart version 2.9.0 (build 2.9.0-16.0.dev 2b917f5b6a)

 
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at /Users/tahatesser/Code/sdk
    • Platform android-29, build-tools 29.0.3
    • ANDROID_HOME = /Users/tahatesser/Code/sdk
    • Java binary at: /Applications/Android
      Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6222593)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.5)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.5, Build version 11E608c
    • CocoaPods version 1.9.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.0)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 46.0.2
    • Dart plugin version 193.7361
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6222593)

[✓] VS Code (version 1.46.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.11.0

[✓] Connected device (5 available)
    • SM M305F      • 32003c30dc19668f          • android-arm64  • Android 10
      (API 29)
    • Taha’s iPhone • 00008020-001059882212002E • ios            • iOS 13.5.1
    • macOS         • macOS                     • darwin-x64     • Mac OS X
      10.15.5 19F101
    • Web Server    • web-server                • web-javascript • Flutter Tools
    • Chrome        • chrome                    • web-javascript • Google Chrome
      83.0.4103.116

• No issues found!

@TahaTesser TahaTesser added dependency: dart Dart team may need to help us found in release: 1.20 Found to occur in 1.20 has reproducible steps The issue has been confirmed reproducible and is ready to work on platform-web Web applications specifically labels Jun 25, 2020
@iapicca iapicca added the framework flutter/packages/flutter repository. See also f: labels. label Jul 8, 2020
@ferhatb ferhatb added the P2 Important issues not at the top of the work list label Jan 8, 2021
@ferhatb
Copy link
Contributor

ferhatb commented Jan 8, 2021

Note: might be breaking change.

@TahaTesser TahaTesser added the c: API break Backwards-incompatible API changes label Jan 12, 2021
Hixie added a commit to Hixie/flutter that referenced this issue Dec 10, 2021
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
@technolion
Copy link

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
Copy link

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;
}

@maheshmnj
Copy link
Member

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
import '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);
        },
      ),
    );
  }
}
logs
Launching 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)
[✓] 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!

@maheshmnj maheshmnj added found in release: 3.3 Found to occur in 3.3 found in release: 3.7 Found to occur in 3.7 and removed found in release: 1.20 Found to occur in 1.20 labels Jan 17, 2023
@ihsanunot
Copy link

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

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: 'Berita Seven',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: TestDepanDasar(),
    );
  }
}

class TestDepanDasar extends StatelessWidget {
  const TestDepanDasar({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Column(
      children: [
        Image.network(
            'https://belajarflutter.com/wp-content/uploads/2022/07/BELAJARFLUTTER.COM_-300x134.png'),
        Container(
          child: Text('Ini gambar'),
        ),
        Container(
          child: Text('Ini Deskripsi'),
        ),
        Container(
          child: Text('Ini Footer'),
        ),
      ],
    ));
  }
}

please somebody help me thanks :)

``

@flutter-triage-bot flutter-triage-bot bot added the triaged-web Triaged by Web platform team label Jul 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: API break Backwards-incompatible API changes dependency: dart Dart team may need to help us found in release: 3.3 Found to occur in 3.3 found in release: 3.7 Found to occur in 3.7 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on P2 Important issues not at the top of the work list platform-web Web applications specifically team-web Owned by Web platform team triaged-web Triaged by Web platform team
Projects
None yet
Development

No branches or pull requests

8 participants