react-native-community/discussions-and-proposals

Improved error messages and also a question/comment about fetch

clarky07 opened this issue · 0 comments

Introduction

Error messages leave something to be desired as has been noted in several other issues. [TypeError: Network request failed] doesn't give much to go on. If we could get more information about what failed that would be helpful

Details

I just spent most of a day on an extremely silly typo error on my part. Frustrating mistake to make, but I accidentally had an extraneous space at the front of a url. This caused fetch to fail with the above error. I was printing out the url i was sending, and it was working everywhere else i tried it (i.e. browser, curl, postman, etc). It wasn't obvious in the console logs that there was a space in front of it.

Feels like an error more like "incorrectly formatted url" or something of that nature should be possible and would be preferable.

As a side note to generally improving error messaging, would there be any drawbacks I'm not thinking of to adding a simple .trim() to the fetch api itself? it feels like it really should have been able to handle this particular error out of the box.

Discussion points

  1. Better error messages are important to the overall usability of react. What is needed to make that a priority?

  2. Are there any downsides to adding .trim() to the url passed into fetch to handle this particularly silly edge case without the need for better error messages.