wcandillon / react-native-expo-image-cache

React Native Image Cache and Progressive Loading based on Expo
MIT License
673 stars 125 forks source link

how to handle broken url? #89

Open thu-san opened 6 years ago

thu-san commented 6 years ago

Is there anyway to handle broken url? Currently it shows warning Cannot download from '...url'

wcandillon commented 6 years ago

What would you like the actual behavior to be?

thu-san commented 6 years ago

Sorry for late reply. I was thinking something like onError props.

<Image
  uri={'broken_url'}
  onError={(e) => console.log}
/>

I edited the src/Image.js like below and using in my project for now, but not sure it is the right approach.

async load({uri, options = {}, onError}: ImageProps): Promise<void> {
  if (uri) {
    try{
      const path = await CacheManager.get(uri, options).getPath();
      if (this.mounted) {
        this.setState({ uri: path });
      }
    }
    catch(e){
      onError(e);
    }
  }
}
MindFreeze commented 5 years ago

I would also expect onError to be called when the request fails. Like 404 or 500. Right now we have no way of knowing and informing the user that the image failed and it just looks like it is still loading.

vtsybulin commented 5 years ago

Pushed this one to address this issue https://github.com/wcandillon/react-native-expo-image-cache/pull/125