Modify generated code to handle error in case target URL does not exist or does not contain an image.