diff options
-rwxr-xr-x | library/SSRS/Soap/NTLM.php | 8 | ||||
-rw-r--r-- | library/SSRS/Soap/ServerException.php | 29 |
2 files changed, 34 insertions, 3 deletions
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 @@ +<?php + +class SSRS_Soap_ServerException extends Exception { + + public $faultcode; + public $faultstring; + public $faultactor; + + static function fromResponse($string) { + $xml = new SimpleXMLElement($string); + $ns = $xml->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 |