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

Commit

Permalink
Added machine level error handling for detecting cURL errors and repo…
Browse files Browse the repository at this point in the history
…rting on them correctly.
  • Loading branch information
nickbart committed Apr 5, 2013
1 parent ad7210d commit bcbbd1e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
50 changes: 50 additions & 0 deletions Exception/Machine.php
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.'
)
);
}
15 changes: 12 additions & 3 deletions Machine/MachineAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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)
{
Expand All @@ -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);

Expand All @@ -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.
*
Expand Down
1 change: 1 addition & 0 deletions Plex.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

require_once(sprintf('%s/Exception/ExceptionInterface.php', $phpPlexDir));
require_once(sprintf('%s/Exception/ExceptionAbstract.php', $phpPlexDir));
require_once(sprintf('%s/Exception/Machine.php', $phpPlexDir));
require_once(sprintf('%s/Machine/MachineInterface.php', $phpPlexDir));
require_once(sprintf('%s/Machine/MachineAbstract.php', $phpPlexDir));
require_once(sprintf('%s/Server.php', $phpPlexDir));
Expand Down

0 comments on commit bcbbd1e

Please sign in to comment.