Added some code to check when the link is not valid (Not Found). Thanks to @pumpudum!