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

Commit

Permalink
feat: Added print of 'curl' error
Browse files Browse the repository at this point in the history
  • Loading branch information
joserick committed Apr 12, 2019
1 parent 21001ce commit 2207ba4
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/Joserick/Plex/Plex.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
* @author <[email protected]> Nick Bartkowiak
* @copyright (c) 2013 Nick Bartkowiak
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU Public Licence (GPLv3)
* @version 0.0.2.5
* @version 0.0.2.6
*/
class Plex
{
Expand Down Expand Up @@ -206,12 +206,16 @@ public function getClient($clientName)
/**
* Returns the token of the sesion plex
*
* @author <[email protected]> José Erick Carreón
*
* @param string $username The username of the Plex server account.
* @param string $password The password of the Plex server account.
*
* @uses Plex::$registerServers()
*
* @return string The token Plex account.
*
* @throws Plex_Exception_Server() Server token not obtained.
*/
public function getToken($username, $password) {
$host = "https://plex.tv/users/sign_in.json";
Expand All @@ -230,8 +234,14 @@ public function getToken($username, $password) {
curl_setopt($process, CURLOPT_POST, 1);
curl_setopt($process, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($process);
$curlError = curl_error($process);
$json = json_decode($data, true);
return $json['user']['authentication_token'];
if ($data === FALSE) {
throw new Plex_Exception_Machine(
'CURL_ERROR',
array(curl_errno($data), curl_error($data))
);
}
curl_close($process);

return json_decode($data, true)['user']['authentication_token'];
}
}

0 comments on commit 2207ba4

Please sign in to comment.