react-native-fetch-blob icon indicating copy to clipboard operation
react-native-fetch-blob copied to clipboard

RNFetchBlob.config().fetch('GET', uri) always returns valid result

Open bbdroid opened this issue 7 years ago • 11 comments

RNFetchBlob.config({}).fetch('GET', uri) function always returns valid result even though I am using invalid image url.(e.g. https://lol.com/lol.png)

React Version : "react": "16.0.0-alpha.6" React Native Version : "react-native": "0.44.0" Library Version : "react-native-fetch-blob": "0.10.2"

  return RNFetchBlob.config({
      path: getPath(uri),
  }).fetch('GET', uri);

  fetchImageUri('https://lol.com/lol.png')
     .then(result => {
       console.log('result = ', result);
     })
     .catch((error) => { console.log(error); });

This always returns valid local image url. So I can get the result of fetching image. It never goes to catch. How can I get the result of fetching image?

Thank you,

bbdroid avatar Aug 17 '17 12:08 bbdroid

https://lol.com/lol.png

bbdroid avatar Aug 17 '17 13:08 bbdroid

Your code sample is incomplete. You return the promise created by the fetch to somewhere outside the screen... And fetchImageUri remains unkown to the rest of us, only you know that function.

lll000111 avatar Aug 17 '17 13:08 lll000111

Ah sorry.

    RNFetchBlob.config({
           path: getPath(uri),
        })
        .fetch('GET', 'https://lol.com/lol.png')
        .then(result => {
           console.log('result = ', result);
        })
        .catch((error) => { console.log(error); });
   }

bbdroid avatar Aug 17 '17 13:08 bbdroid

Is there any solution?

bbdroid avatar Aug 17 '17 13:08 bbdroid

No. I wrote a test case for the test package for RNFB for someone to continue from here.

I found that timeouts behave strangely: I cannot really test them well. They work if you configure a timeout in RNFetchBlob.config - as long as that timeout is shorter than the one you get from the system. A "real" timeout without having one configured doesn't trigger a rejected promise and the test system doesn't know how to deal with it and shows nothing but "timeout" for the entire test, without any actual results.

The problem can be reproduced with other, non-timeout related request failures as well, which I use below.

describe('#492 RNFetchBlob.fetch always resolves with valid result', (report, done) => {
  // 404 Not Found
  RNFetchBlob.fetch('GET', TEST_SERVER_URL + '/INVALID')
  .then(result => {
    report(
      <Assert key="Invalid URL should have caused error" expect={false} actual={true}/>,
      <Info key="Response data for fetch error test">
        <Text>{JSON.stringify(result)}</Text>
      </Info>
    )
    done()
  })
  .catch((error) => {
    report(
      <Assert key="Invalid URL causes error" expect={true} actual={true}/>,
      <Info key="Error">
        <Text>{String(error)}</Text>
      </Info>
    )
    done()
  });
})

Result

image

lll000111 avatar Aug 17 '17 14:08 lll000111

Hmm... This can't be the actual solution.

bbdroid avatar Aug 17 '17 14:08 bbdroid

Of course not. I said

I wrote a test case for the test package for RNFB

I don't know how you expect bug fixing to work, the way I know it to work best is to have a test case that's part of ones existing test framework. If you look at the RNFB test repo you'll see that it already contains numerous test cases specifically made for issues such as yours, starting with #[issue number] in the test description. I'm sorry if you don't see the value and expected an immediate resolution.

lll000111 avatar Aug 17 '17 14:08 lll000111

@lll000111 , thanks for the great help 👍 let me run the test and figure out what's going on 😄

wkh237 avatar Aug 17 '17 15:08 wkh237

@bdavid68 @lll000111 I think this is by designed. Quote from OkHttp's document

Note that transport-layer success (receiving a HTTP response code, headers and body) does not necessarily indicate application-layer success: response may still indicate an unhappy HTTP response code like 404 or 500.

So basically, you can check the status in res.info() then deal with it, instead of try to catch the error.

wkh237 avatar Aug 17 '17 15:08 wkh237

Thanks @wkh237 ! I will try it.

bbdroid avatar Aug 17 '17 15:08 bbdroid

It seems still present ("react-native-fetch-blob": "0.10.8").

JulienMalige avatar May 28 '18 16:05 JulienMalige