Suppressing mediaResource.getById exception when requesting an item that has been deleted
I have a custom listview that renders a list of news articles along with the image associated with the article. An error has been reported and it turns out it is due to the fact that someone has deleted the media item associated with one of the articles. I can handle the missing image in the display by showing a placeholder but what I can't seem to do is stop the underlying exception bubbling up to the user.
The errors seems to occur when calling mediaResource.getById() in the following code:
if (imgProp.value.length) {
mediaResource.getById(imgProp.value).then(function (media) {
item.image = mediaHelper.resolveFile(media, false) + "?width=400&height=240&mode=crop";
},
function (e) {
console.error(e);
});
}
I have tried wrapping it in a try/catch block but the error is still very visible to the user. Is there anything I can do to prevent the user seeing the error?
Thanks for the reply Tarik but I don't feel that this is going to be a very scalable solution as the media library could become significant in size over time.
Suppressing mediaResource.getById exception when requesting an item that has been deleted
I have a custom listview that renders a list of news articles along with the image associated with the article. An error has been reported and it turns out it is due to the fact that someone has deleted the media item associated with one of the articles. I can handle the missing image in the display by showing a placeholder but what I can't seem to do is stop the underlying exception bubbling up to the user.
The errors seems to occur when calling
mediaResource.getById()
in the following code:I have tried wrapping it in a try/catch block but the error is still very visible to the user. Is there anything I can do to prevent the user seeing the error?
Thanks, Simon
I suggest to get the available media items first by using the code below and then call the
mediaResource.getById()
when exist.Thanks for the reply Tarik but I don't feel that this is going to be a very scalable solution as the media library could become significant in size over time.
Then, I suggest to do a search in
Media
to restrict the source of articles' images.is working on a reply...