Skip to content
This repository was archived by the owner on Jun 9, 2023. It is now read-only.

Commit 2207ba4

Browse files
committed
feat: Added print of 'curl' error
1 parent 21001ce commit 2207ba4

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/Joserick/Plex/Plex.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
* @author <[email protected]> Nick Bartkowiak
7979
* @copyright (c) 2013 Nick Bartkowiak
8080
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU Public Licence (GPLv3)
81-
* @version 0.0.2.5
81+
* @version 0.0.2.6
8282
*/
8383
class Plex
8484
{
@@ -206,12 +206,16 @@ public function getClient($clientName)
206206
/**
207207
* Returns the token of the sesion plex
208208
*
209+
* @author <[email protected]> José Erick Carreón
210+
*
209211
* @param string $username The username of the Plex server account.
210212
* @param string $password The password of the Plex server account.
211213
*
212214
* @uses Plex::$registerServers()
213215
*
214216
* @return string The token Plex account.
217+
*
218+
* @throws Plex_Exception_Server() Server token not obtained.
215219
*/
216220
public function getToken($username, $password) {
217221
$host = "https://plex.tv/users/sign_in.json";
@@ -230,8 +234,14 @@ public function getToken($username, $password) {
230234
curl_setopt($process, CURLOPT_POST, 1);
231235
curl_setopt($process, CURLOPT_RETURNTRANSFER, true);
232236
$data = curl_exec($process);
233-
$curlError = curl_error($process);
234-
$json = json_decode($data, true);
235-
return $json['user']['authentication_token'];
237+
if ($data === FALSE) {
238+
throw new Plex_Exception_Machine(
239+
'CURL_ERROR',
240+
array(curl_errno($data), curl_error($data))
241+
);
242+
}
243+
curl_close($process);
244+
245+
return json_decode($data, true)['user']['authentication_token'];
236246
}
237247
}

0 commit comments

Comments
 (0)