question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cannot catch error from fetch call when used a malformed URL

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:9

github_iconTop GitHub Comments

2reactions
kseglacommented, Feb 26, 2018

fetch has been having this very bad problem for some time now, crashing apps in production whenever something it doesn’t like happen. At this point, I’m looking for good alternatives 😦

0reactions
kelsetcommented, Dec 17, 2018

This issue has been inactive for a very long time, closing. There are newer and more active issues on this subject.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fetch response malformed - javascript - Stack Overflow
The issue is basically that the fetch response object is not correct. Pictures to clarify the issue are below as it is hard...
Read more >
Handling Failed HTTP Responses With fetch() - TJ VanToll
Per MDN, the fetch() API only rejects a promise when a “network error is encountered, although this usually means permissions issues or similar....
Read more >
Handling operation errors - Apollo GraphQL Docs
Apollo Client can encounter a variety of errors when executing operations on your GraphQL server. Apollo Client helps you handle these errors according...
Read more >
HTTP status and error codes for JSON | Cloud Storage
The following document provides reference information about the status codes and error messages that are used in the Cloud Storage JSON API.
Read more >
Guide to Spring Boot REST API Error Handling - Toptal
Using JERSY(@path attribute), not able to handle exceptions. Not using @requestmapping and RestExceptionHandler not handling this. Can you please help on this.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found