From a2b0ffb492bbd963e3e5bdc8e6bedbaa0060f10f Mon Sep 17 00:00:00 2001 From: "arron.woods@gmail.com" Date: Mon, 1 Oct 2012 16:26:47 +0000 Subject: Server exception --- library/SSRS/Soap/NTLM.php | 8 +++++--- library/SSRS/Soap/ServerException.php | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 library/SSRS/Soap/ServerException.php diff --git a/library/SSRS/Soap/NTLM.php b/library/SSRS/Soap/NTLM.php index 0562c6d..929a642 100755 --- a/library/SSRS/Soap/NTLM.php +++ b/library/SSRS/Soap/NTLM.php @@ -47,7 +47,7 @@ class SSRS_Soap_NTLM extends SoapClient { return $this->_uri; } - public function setCacheExpiry($cacheExpiry=86400) { + public function setCacheExpiry($cacheExpiry = 86400) { $this->_cacheExpiry = $cacheExpiry; return $this; } @@ -141,7 +141,7 @@ class SSRS_Soap_NTLM extends SoapClient { curl_setopt($handle, CURLOPT_POSTFIELDS, $data); } - if($action !== null){ + if ($action !== null) { $headers[] = 'SOAPAction: "' . $action . '"'; } @@ -153,7 +153,9 @@ class SSRS_Soap_NTLM extends SoapClient { } $httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE); - if ($httpCode !== 200) { + if ($httpCode >= 300 && $httpCode <= 600) { + throw SSRS_Soap_ServerException::fromResponse($response); + } else if ($httpCode !== 200) { throw new SSRS_Soap_Exception('HTTP error: ' . $httpCode . ' ' . $response, $httpCode, $response); } curl_close($handle); diff --git a/library/SSRS/Soap/ServerException.php b/library/SSRS/Soap/ServerException.php new file mode 100644 index 0000000..3ffce47 --- /dev/null +++ b/library/SSRS/Soap/ServerException.php @@ -0,0 +1,29 @@ +getNamespaces(true); + + $soap = $xml->children($ns['soap']); + $body = $soap->Body->children($ns['soap']); + if (isset($body->Fault)) { + $fault = $body->Fault->children(); + + $exception = new SSRS_Soap_ServerException((string) $fault->faultstring); + $exception->faultcode = (string) $fault->faultcode; + $exception->faultstring = (string) $fault->faultstring; + $exception->faultactor = (string) $fault->faultactor; + } else { + throw new SSRS_Soap_Exception('Invalid server response'); + } + + return $exception; + } + +} \ No newline at end of file -- cgit v1.1