22
33namespace App \Http \Controllers ;
44
5+ use App \Exceptions \TwitchFormatException ;
56use Illuminate \Http \Request ;
67
78use App \Http \Requests ;
@@ -62,12 +63,12 @@ class TwitchController extends Controller
6263 private $ twitchApi ;
6364
6465 /**
65- * @var App\Repositories\ TwitchApiRepository
66+ * @var TwitchApiRepository
6667 */
6768 private $ api ;
6869
6970 /**
70- * @var App\Repositories\ TwitchEmotesApiRepository
71+ * @var TwitchEmotesApiRepository
7172 */
7273 private $ emotes ;
7374
@@ -79,7 +80,10 @@ class TwitchController extends Controller
7980 private $ version = ['Accept ' => 'application/vnd.twitchtv.v5+json ' ];
8081
8182 /**
82- * Initiliazes the controller with a reference to TwitchApiController.
83+ * Initializes the controller with a reference to TwitchApiController.
84+ *
85+ * @param TwitchApiRepository $apiRepository
86+ * @param TwitchEmotesApiRepository $emotesApi
8387 */
8488 public function __construct (TwitchApiRepository $ apiRepository , TwitchEmotesApiRepository $ emotesApi )
8589 {
@@ -847,19 +851,19 @@ public function gameOrStatus(Request $request, $route, $channel = null)
847851 }
848852 }
849853
850- $ getGame = $ this ->twitchApi ->channels ($ channel , $ this ->version );
851-
852- // Invalid API response
853- if (empty ($ getGame )) {
854+ try {
855+ $ getChannel = $ this ->api ->channelById ($ channel );
856+ } catch (TwitchApiException $ ex ) {
854857 return Helper::text (__ ('generic.error_loading_data_api ' ));
858+ } catch (TwitchFormatException $ ex ) {
859+ return Helper::text ($ ex ->getMessage ());
855860 }
856861
857- if (isset ( $ getGame [ ' message ' ]) ) {
858- return Helper::text (sprintf ( ' %s - %s ' , $ getGame [ ' error ' ], $ getGame [ ' message ' ]) );
862+ if ($ route === ' game ' ) {
863+ return Helper::text ($ getChannel [ ' game ' ][ ' name ' ] ?: '' );
859864 }
860865
861- $ text = $ getGame [$ route ];
862- return Helper::text ($ text ?: '' );
866+ return Helper::text ($ getChannel ['title ' ]);
863867 }
864868
865869 /**
0 commit comments