Skip to content

Commit

Permalink
Modified error handling on missing gym image
Browse files Browse the repository at this point in the history
The script no longer crashes when a gym image is missing and instead uses the fallback image.
Also improved error reporting in this case
  • Loading branch information
Ninjasoturi committed Feb 23, 2022
1 parent f107433 commit e606f52
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions raidpicture.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
}
// Create GD image object from given URI regardless of file type
function grab_img($uri){
$img = imagecreatefromstring(file_get_contents($uri));
if ($img === false) {
try {
$img = imagecreatefromstring(file_get_contents($uri));
} catch (Exception $e) {
info_log($uri, 'Failed to get image:');
info_log($e->getMessage(), 'Reason: ');
return false;
}
return $img;
Expand Down Expand Up @@ -124,15 +126,15 @@ function grab_img($uri){
}
}
}
$img_gym = grab_img($gym_image_path);
}else {
$img_gym = false;
if (!empty($gym_url)) {
$img_gym = grab_img($gym_url);
$gym_image_path = $gym_url;
}
}
$img_gym = grab_img($gym_image_path);
if($img_gym == false) {
info_log($img_gym, 'Loading the gym image failed, using default gym image');
info_log($gym_image_path, 'Loading the gym image failed, using default gym image');
if(is_file($config->RAID_DEFAULT_PICTURE)) {
$img_gym = grab_img($config->RAID_DEFAULT_PICTURE);
} else {
Expand Down

0 comments on commit e606f52

Please sign in to comment.