Skip to content

Commit 34e696b

Browse files
committed
[Misc] Add better failure checks for empty values
1 parent 34e5340 commit 34e696b

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

app/Http/Controllers/MiscController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ public function currency(Request $request)
7171
return Helper::text('An error has occurred retrieving exchange rates');
7272
}
7373

74+
if (empty($convert)) {
75+
return Helper::text('An error has occurred retrieving exchange rates');
76+
}
77+
7478
if ($convert['success'] === false) {
7579
if (!empty($convert['error'])) {
7680
return Helper::text('An error occurred retrieving exchange rates: ' . $convert['error']['type']);

app/Http/Controllers/TwitchController.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,11 @@ public function gameOrStatus(Request $request, $route, $channel = null)
848848

849849
$getGame = $this->twitchApi->channels($channel, $this->version);
850850

851+
// Invalid API response
852+
if (empty($getGame)) {
853+
return Helper::text(__('generic.error_loading_data_api'));
854+
}
855+
851856
if (isset($getGame['message'])) {
852857
return Helper::text(sprintf('%s - %s', $getGame['error'], $getGame['message']));
853858
}
@@ -1652,6 +1657,11 @@ public function subcount(Request $request, $subcount = null, $channel = null)
16521657

16531658
$data = $this->twitchApi->channelSubscriptions($user->id, $token, 1, 0, 'asc', $this->version);
16541659

1660+
// Invalid API response
1661+
if (empty($data)) {
1662+
return Helper::text(__('generic.error_loading_data_api'));
1663+
}
1664+
16551665
if (!empty($data['status'])) {
16561666
if ($data['status'] === 401) {
16571667
return Helper::text($needToReAuth);
@@ -1854,6 +1864,11 @@ public function subEmotes(Request $request, $channel = null)
18541864
return Helper::text('Error occurred retrieving user information for Twitch user: ' . $channel);
18551865
}
18561866

1867+
// API returned an empty response, most likely disabled/banned user or it doesn't exist.
1868+
if (empty($user)) {
1869+
return Helper::text(__('twitch.user_not_found', ['user' => $channel]));
1870+
}
1871+
18571872
if (!empty($user['message'])) {
18581873
return Helper::text($user['message']);
18591874
}

0 commit comments

Comments
 (0)