Handle no image being returned by tinyfox.dev

This commit is contained in:
floppydiskette 2024-12-09 20:48:27 +00:00
parent 20c16b7908
commit fe433ae802
Signed by: fwoppydwisk
SSH key fingerprint: SHA256:Hqn452XQ1ETzUt/FthJu6+OFkS4NBxCv5VQSEvuk7CE
2 changed files with 10 additions and 3 deletions

View file

@ -21,7 +21,9 @@ public function getWah(): string {
try { try {
$response = Http::get('https://api.tinyfox.dev/img.json?animal=wah'); $response = Http::get('https://api.tinyfox.dev/img.json?animal=wah');
$data = $response->json(); $data = $response->json();
return "https://api.tinyfox.dev".$data["loc"]; if ($data == null) return "";
return "https://api.tinyfox.dev" . $data["loc"];
} catch (Exception $ex) { } catch (Exception $ex) {
return ""; return "";
} }

View file

@ -1,5 +1,10 @@
<div class="wah"> <div class="wah">
<h3>Random Wah!</h3> <h3>Random Wah!</h3>
<img src="{{ $wah }}"> @if ($wah !== "")
<img src="{{ $wah }}" alt="Random image featuring a Red Panda">
<p>Image "stolen" from <a href="https://tinyfox.dev/">tinyfox.dev</a></p> <p>Image "stolen" from <a href="https://tinyfox.dev/">tinyfox.dev</a></p>
@else
<img src="https://placehold.co/250x250" alt="250x250 Placeholder Image">
<p>Unable to retrieve image</p>
@endif
</div> </div>