Invision Community 4: SEO, prepare for v5 and dormant account notifications By Matt Monday at 02:04 PM
Essential+ Posted May 20, 2015 Posted May 20, 2015 Hi, I am using IPB 4, and I am making a request to the steam API to retrieve stats for a game.$playerData = \IPS\Http\Url::external("http://api.steampowered.com/ISteamUserStats/GetUserStatsForGame/v0002/?appid=221380&key=".$loginHandler->settings['st_api_key']."&steamid=".$this->member->st_id."&format=json")->request()->get()->decodeJson(); The only problem is that depending on the User it won't retrieve a valid Json file if there isn't any game data. How can I have this code catch an exception or check if it's a valid json file before decoding?
Marcher Technologies Posted May 20, 2015 Posted May 20, 2015 try{ $playerData = \IPS\Http\Url::external("http://api.steampowered.com/ISteamUserStats/GetUserStatsForGame/v0002/?appid=221380&key=".$loginHandler->settings['st_api_key']."&steamid=".$this->member->st_id."&format=json")->request()->get()->decodeJson(); } catch(\RuntimeException $e) { //handle it }
Recommended Posts
Archived
This topic is now archived and is closed to further replies.