commit c51df8498230a5fbc2417c908afa136d0f582335
parent 2c39b18581f9a24ed70bb231580c79bebe0b64c5
Author: Jan Dankert <develop@jandankert.de>
Date: Wed, 6 Nov 2019 23:20:27 +0100
Refactoring: Forward CMS errors to the DAV client.
Diffstat:
6 files changed, 77 insertions(+), 18 deletions(-)
diff --git a/cms/Client.class.php b/cms/Client.class.php
@@ -1,6 +1,9 @@
<?php
+use dav\exception\CMSServerError;
+use dav\exception\CMSForbiddenError;
+
class Client
{
public $useCookies = false;
@@ -154,9 +157,19 @@ class Client
}
fclose($fp); // Verbindung brav schlie�en.
- if ( @$status != '200' )
+ if ( @$status == '200' )
+ ; // OK
+ elseif ( @$status != '403' )
+ {
+ throw new CMSForbiddenError('CMS: Forbidden'."$line\n".$body);
+ }
+ elseif ( @$status[0] == '5' )
+ {
+ throw new CMSServerError('Internal CMS Error'."$line\n".$body);
+ }
+ else
{
- throw new RuntimeException('Server-Status != 200: '."$line\n".$body);
+ throw new RuntimeException('Server-Status: '.@$status."$line\n".$body);
}
foreach( $this->responseHeader as $headerName => $headerValue)
diff --git a/dav.php b/dav.php
@@ -36,7 +36,9 @@ require('./config.php');
require('./cms/Client.class.php');
require('./cms/CMS.class.php');
-require('./dav/NotFoundException.php');
+require('./dav/exception/NotFoundException.php');
+require('./dav/exception/CMSForbiddenError.php');
+require('./dav/exception/CMSServerError.php');
require('./dav/Logger.class.php');
require('./dav/URIParser.class.php');
require('./dav/DAV.class.php');
@@ -69,12 +71,28 @@ try {
$davAction = $davClass->newInstance();
$davAction->execute();
}
+catch( \dav\exception\CMSForbiddenError $e )
+{
+ error_log('WEBDAV ERROR: '.$e->getMessage()."\n".$e->getTraceAsString() );
+
+ // Wir teilen dem Client mit, dass auf dem Server was schief gelaufen ist.
+ header('HTTP/1.1 403 Forbidden');
+ echo 'WebDAV-Request failed'."\n".$e->getTraceAsString();
+}
+catch( \dav\exception\CMSServerError $e )
+{
+ error_log('WEBDAV ERROR: '.$e->getMessage()."\n".$e->getTraceAsString() );
+
+ // Wir teilen dem Client mit, dass auf dem Server was schief gelaufen ist.
+ header('HTTP/1.1 503 CMS Server Error');
+ echo 'WebDAV-Request failed'."\n".$e->getTraceAsString();
+}
catch( Exception $e )
{
error_log('WEBDAV ERROR: '.$e->getMessage()."\n".$e->getTraceAsString() );
// Wir teilen dem Client mit, dass auf dem Server was schief gelaufen ist.
- header('HTTP/1.1 503 Internal WebDAV Server Error');
+ header('HTTP/1.1 503 Internal DAV Error');
echo 'WebDAV-Request failed'."\n".$e->getTraceAsString();
}
diff --git a/dav/NotFoundException.php b/dav/NotFoundException.php
@@ -1,13 +0,0 @@
-<?php
-
-namespace dav\exception;
-
-use Exception;
-
-class NotFoundException extends Exception
-{
- public function __construct($message = "")
- {
- parent::__construct($message);
- }
-}-
\ No newline at end of file
diff --git a/dav/exception/CMSForbiddenError.php b/dav/exception/CMSForbiddenError.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace dav\exception;
+
+use Exception;
+
+class CMSForbiddenError extends Exception
+{
+ public function __construct($message = "")
+ {
+ parent::__construct($message);
+ }
+}+
\ No newline at end of file
diff --git a/dav/exception/CMSServerError.php b/dav/exception/CMSServerError.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace dav\exception;
+
+use Exception;
+
+class CMSServerError extends Exception
+{
+ public function __construct($message = "")
+ {
+ parent::__construct($message);
+ }
+}+
\ No newline at end of file
diff --git a/dav/exception/NotFoundException.php b/dav/exception/NotFoundException.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace dav\exception;
+
+use Exception;
+
+class NotFoundException extends Exception
+{
+ public function __construct($message = "")
+ {
+ parent::__construct($message);
+ }
+}+
\ No newline at end of file