This repository has been archived by the owner on Jun 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added machine level error handling for detecting cURL errors and repo…
…rting on them correctly.
- Loading branch information
Showing
3 changed files
with
63 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
/** | ||
* Plex Exception (Plexception) | ||
* | ||
* @category php-plex | ||
* @package Plex_Exception | ||
* @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 | ||
* | ||
* This file is part of php-plex. | ||
* | ||
* php-plex is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* php-plex is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
*/ | ||
|
||
/** | ||
* Exception to be thrown for any problems at the machine level. | ||
* | ||
* @category php-plex | ||
* @package Plex_Exception | ||
* @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 | ||
*/ | ||
class Plex_Exception_Machine extends Plex_ExceptionAbstract | ||
{ | ||
/** | ||
* List of valid exception types for the machine exception class. | ||
* @var mixed[] | ||
*/ | ||
protected $validTypes = array( | ||
// For any errors that happen during a cURL connection to a plex | ||
// Plex machine. | ||
'CURL_ERROR' => array( | ||
'code' => 500, | ||
'message' => 'There was a cURL error: (%d) %s.' | ||
) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,9 @@ | |
* @category php-plex | ||
* @package Plex_Machine | ||
* @author <[email protected]> Nick Bartkowiak | ||
* @copyright (c) 2012 Nick Bartkowiak | ||
* @copyright (c) 2013 Nick Bartkowiak | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU Public Licence (GPLv3) | ||
* @version 0.0.1 | ||
* @version 0.0.2 | ||
* | ||
* This file is part of php-plex. | ||
* | ||
|
@@ -110,6 +110,8 @@ protected function xmlAttributesToArray($xml) | |
* @param string $url The URL to which the request is to be made. | ||
* | ||
* @return SimpleXMLElement An XML document from a Plex machine. | ||
* | ||
* @throws Plex_Exception_Machine | ||
*/ | ||
protected function makeCall($url) | ||
{ | ||
|
@@ -120,6 +122,13 @@ protected function makeCall($url) | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); | ||
|
||
$response = curl_exec($ch); | ||
|
||
if ($response === FALSE) { | ||
throw new Plex_Exception_Machine( | ||
'CURL_ERROR', | ||
array(curl_errno($ch), curl_error($ch)) | ||
); | ||
} | ||
|
||
curl_close($ch); | ||
|
||
|
@@ -130,7 +139,7 @@ protected function makeCall($url) | |
|
||
/** | ||
* Universal function so any method belonging to a child class of a Plex | ||
* machine can discover which fucntion called it. This is used mainly for | ||
* machine can discover which function called it. This is used mainly for | ||
* some of our polymorphic requests as the calling function can tell us what | ||
* type of item is being requested. | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters