rembrandt icon indicating copy to clipboard operation
rembrandt copied to clipboard

On load fail handling

Open aiboost opened this issue 7 years ago • 1 comments

Hi,

Now there is no handling if one of specified images was NOT loaded (I tell about browser implementation). This is bad for frontend applications not to have ability to handle such errors: if URL returns 404, the application just will discontinue working in the silence.

As I see the code:

const browserImage = Utils.createImage()
browserImage.addEventListener('load', () => {
   resolve(Image.fromImage(browserImage))
})
browserImage.crossOrigin = 'Anonymous'
browserImage.src = image

you use DOM API to load image. So you can at least use this to handle failures: https://stackoverflow.com/questions/9815762/detect-when-an-image-fails-to-load-in-javascript

But looks like this solution is not cross-browser (see link). I suppose the best solution is to use File API. I've tried to do this by myself, but I unable to convert read binary PNG (or any other format) data to BLOB to pass it to FileReader. Maybe you will get luck with this.

aiboost avatar Aug 09 '17 14:08 aiboost

And one another pitfall for loading loading images data inside tag: if you use some API and load image at one URL many times, you will see that browser caches images and you can not be sure that image was really reloaded. Adding "?someUniqId" is not possible in some cases (you can break API URL format, this works guaranteed fine only if you request static files and only if there are no custom server limits).

aiboost avatar Aug 10 '17 11:08 aiboost