I’m pulling in external image files in a repeater. However, because the URLs are being supplied by members, I want to be able to able to control what is displayed if the file at the end of the URL turns out not to be an image (rather than just do basic validation on the string for https://, jpg etc).
Currently when I pass a bad link to image.src, I get a Wix SDK error in the console, and the image doesn’t show, but I haven’t found a way to catch this error in my code so I can display something else in that scenario. The workaround I’ve been using is to have an 'image URL Error" image behind the dynamic image, which only gets seen if the dynamic one doesn’t show, but I need something a bit more flexible.
So I’d be looking for something like the below, but the try/catch doesn’t work, possibly because the error is non lethal - or perhaps because my code is bad?
Thank you for any advice !
Tom
export function showImageByUrl(imageTarget, imageUrl) {
Thanks ! Actually I just put in the displayImageError as a placeholder to show where it should fire, though of course you’re right I’d missed the brackets. The problem is that the Catch doesn’t fire when I use a bad URL - I’m actually using Console Log as below at the moment - though it never fires, I just get: "Wix code SDK error: The “src” property cannot be set to “…etc” in the console.
@benibrodi first you try to assign the value, and if the link doesn’t fit the assignment fails (“src” property cannot be set to…" ).
Then you check if the assignment failed or not. Doesn’t make sense?