[Pkg-owncloud-commits] [owncloud] 02/23: Adding request specific exception handling - now with WebDAV responses - refs #17192

David Prévot taffit at moszumanska.debian.org
Tue Jul 7 12:42:51 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch stable8
in repository owncloud.

commit 526a45be189c5f30ffd4a540f34cf161c5ed2223
Author: Thomas Müller <thomas.mueller at tmit.eu>
Date:   Mon Jun 29 15:47:05 2015 +0200

    Adding request specific exception handling - now with WebDAV responses - refs #17192
---
 remote.php | 40 +++++++++++++++++++++++++++++++++-------
 1 file changed, 33 insertions(+), 7 deletions(-)

diff --git a/remote.php b/remote.php
index c1077e4..5b4f6e1 100644
--- a/remote.php
+++ b/remote.php
@@ -25,6 +25,38 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>
  *
  */
+
+use OC\Connector\Sabre\ExceptionLoggerPlugin;
+use Sabre\DAV\Exception\ServiceUnavailable;
+use Sabre\DAV\Server;
+
+/**
+ * @param Exception $e
+ */
+function handleException(Exception $e) {
+	$request = \OC::$server->getRequest();
+	// in case the request content type is text/xml - we assume it's a WebDAV request
+	if ($request->getHeader('Content-Type') === 'text/xml') {
+		// fire up a simple server to properly process the exception
+		$server = new Server();
+		$server->addPlugin(new ExceptionLoggerPlugin('webdav', \OC::$server->getLogger()));
+		$server->on('beforeMethod', function () use ($e) {
+			$class = get_class($e);
+			$msg = $e->getMessage();
+			throw new ServiceUnavailable("$class: $msg");
+		});
+		$server->exec();
+	} else {
+		if ($e instanceof \OC\ServiceUnavailableException ) {
+			OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE);
+		} else {
+			OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR);
+		}
+		\OCP\Util::writeLog('remote', $e->getMessage(), \OCP\Util::FATAL);
+		OC_Template::printExceptionErrorPage($e);
+	}
+}
+
 try {
 	require_once 'lib/base.php';
 
@@ -82,12 +114,6 @@ try {
 	$baseuri = OC::$WEBROOT . '/remote.php/'.$service.'/';
 	require_once $file;
 
-} catch (\OC\ServiceUnavailableException $ex) {
-	OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE);
-	\OCP\Util::writeLog('remote', $ex->getMessage(), \OCP\Util::FATAL);
-	OC_Template::printExceptionErrorPage($ex);
 } catch (Exception $ex) {
-	OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR);
-	\OCP\Util::writeLog('remote', $ex->getMessage(), \OCP\Util::FATAL);
-	OC_Template::printExceptionErrorPage($ex);
+	handleException($ex);
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list