Skip to content

cannot catch error from fetch call when used a malformed URL #18087

@Trenrod

Description

@Trenrod

Is this a bug report?

Yes

Have you read the Contributing Guidelines?

Yes

Environment

Environment:
OS: Windows 10
Node: 6.12.3
Yarn: Not Found
npm: 3.10.10
Watchman: Not Found
Xcode: N/A
Android Studio: Version 3.0.0.0 AI-171.4443003

Packages: (wanted => installed)
react: 16.2.0 => 16.2.0
react-native: 0.53.3 => 0.53.3

Target Platform: Android 6 Emulator (From the Getting Started howto)

Steps to Reproduce

Cannot catch the fetch call when used a malformed url.

  1. Call fetch() with a malformed url like 'asd' or 'https:://facebook.github.io'
  2. try to catch with '.catch' when called as promise or try/catch within async/await

Expected Behavior

catch should be executed

Actual Behavior

red screen shows up with "unexpected url: [URL USED WITHIN THE CALL]"

grafik

Reproducible Demo

  async asyncFetch(url) {
    try {
      console.log('DEBUG - START FETCHING');
      const response = await fetch(url);
      console.log('DEBUG - END FETCHING');
      const xml = await response.text();
      const json = xml2json.parse(xml);
      return { data: json };
    } catch (error) {
      console.log('DEBUG - START ERROR: ' + error.message);
      throw error;
    }
  }

  const url = 'httasd:afdasdfads';
  this.asyncFetch(url)
  .catch(err => {
    console.log('DEBUG - Error: ' + err.message);
  })

Actual console output is:
DEBUG - START FETCHING

Note: Same issue like #17843

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions