Commit 9ae03bfb authored by Michael Niewoehner's avatar Michael Niewoehner

ZP-1058 autodiscover: Rework exception handling to match z-push core.

Released under the Affero GNU General Public License (AGPL) version
3.
parent 1c560eca
...@@ -104,7 +104,20 @@ class ZPushAutodiscover { ...@@ -104,7 +104,20 @@ class ZPushAutodiscover {
} }
} }
catch (AuthenticationRequiredException $ex) { catch (Exception $ex) {
// Extract any previous exception message for logging purpose.
$exclass = get_class($ex);
$exception_message = $ex->getMessage();
if($ex->getPrevious()){
do {
$current_exception = $ex->getPrevious();
$exception_message .= ' -> ' . $current_exception->getMessage();
} while($current_exception->getPrevious());
}
ZLog::Write(LOGLEVEL_FATAL, sprintf('Exception: (%s) - %s', $exclass, $exception_message));
if ($ex instanceof AuthenticationRequiredException) {
if (isset($incomingXml)) { if (isset($incomingXml)) {
// log the failed login attemt e.g. for fail2ban // log the failed login attemt e.g. for fail2ban
if (defined('LOGAUTHFAIL') && LOGAUTHFAIL != false) if (defined('LOGAUTHFAIL') && LOGAUTHFAIL != false)
...@@ -116,7 +129,7 @@ class ZPushAutodiscover { ...@@ -116,7 +129,7 @@ class ZPushAutodiscover {
http_response_code(401); http_response_code(401);
header('WWW-Authenticate: Basic realm="ZPush"'); header('WWW-Authenticate: Basic realm="ZPush"');
} }
catch (ZPushException $ex) { else if ($ex instanceof ZPushException) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("Unable to complete autodiscover because of ZPushException. Error: %s", $ex->getMessage())); ZLog::Write(LOGLEVEL_ERROR, sprintf("Unable to complete autodiscover because of ZPushException. Error: %s", $ex->getMessage()));
if(!headers_sent()) { if(!headers_sent()) {
header('HTTP/1.1 '. $ex->getHTTPCodeString()); header('HTTP/1.1 '. $ex->getHTTPCodeString());
...@@ -127,6 +140,7 @@ class ZPushAutodiscover { ...@@ -127,6 +140,7 @@ class ZPushAutodiscover {
} }
$this->sendResponse($response); $this->sendResponse($response);
} }
}
/** /**
* Processes the incoming XML request and parses it to a SimpleXMLElement. * Processes the incoming XML request and parses it to a SimpleXMLElement.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment