Skip to content

Commit

Permalink
Set soap client on soap fault exceptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Gauthier committed Feb 26, 2009
1 parent 3ee3a91 commit 1b50aa5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
18 changes: 12 additions & 6 deletions Payment/PayPal/SOAP.php
Expand Up @@ -359,14 +359,20 @@ public function __construct(array $options)
*/
public function call($requestName, $arguments = array())
{
try {
$client = $this->getSoapClient();
$client = $this->getSoapClient();

// Use a unique client. If an exception is thrown, state will be
// preserved if subsequent requests are made.
$client = clone $client;

$headers = $this->getSoapHeaders();

try {
$response = $client->__soapCall(
$requestName,
array($arguments),
null,
$this->getSoapHeader()
$headers
);

if (isset($response->Errors)) {
Expand Down Expand Up @@ -409,8 +415,6 @@ public function call($requestName, $arguments = array())
);
}
}

return $response;
} catch (SoapFault $e) {
$message = $e->getMessage();

Expand Down Expand Up @@ -439,8 +443,10 @@ public function call($requestName, $arguments = array())

// Unknown SOAP exception, pass it along.
throw new Payment_PayPal_SOAP_FaultException('PayPal SOAP Error: ' .
$e->getMessage(), $e->getCode(), $e);
$e->getMessage(), $e->getCode(), $e, $client);
}

return $response;
}

// }}}
Expand Down
34 changes: 29 additions & 5 deletions Payment/PayPal/SOAP/Exceptions.php
Expand Up @@ -273,20 +273,31 @@ class Payment_PayPal_SOAP_FaultException extends
*/
private $_soapFault = null;

/**
* The SOAP client that caused the exception
*
* @var SoapClient
* @see Payment_PayPal_SOAP_FaultException::getSoapClient()
*/
private $_soapClient = null;

// }}}
// {{{ public function __construct()

/**
* Creates a new PayPal SOAP fault exception
*
* @param string $message the exception message.
* @param integer $code the exception code.
* @param SoapFault $soapFault the original SoapFault.
* @param string $message the exception message.
* @param integer $code the exception code.
* @param SoapFault $soapFault the original SoapFault.
* @param SoapClient $soapClient the SOAP client that caused the fault.
*/
public function __construct($message, $code, SoapFault $soapFault)
public function __construct($message, $code, SoapFault $soapFault,
SoapClient $soapClient)
{
parent::__construct($message, $code);
$this->_soapFault = $soapFault;
$this->_soapFault = $soapFault;
$this->_soapClient = $soapClient;
}

// }}}
Expand All @@ -303,6 +314,19 @@ public function getSoapFault()
return $this->_soapFault;
}

// }}}
// {{{ getSoapClient()

/**
* Gets the original SOAP client that caused the exception
*
* @return SoapClient the SOAP client that caused the exception.
*/
public function getSoapClient()
{
return $this->_soapClient;
}

// }}}
}

Expand Down

0 comments on commit 1b50aa5

Please sign in to comment.