]> source.dussan.org Git - nextcloud-server.git/commitdiff
return proper error code when reporting exception fails in remote.php 34584/head
authorRobin Appelman <robin@icewind.nl>
Wed, 5 Oct 2022 10:39:00 +0000 (12:39 +0200)
committerRobin Appelman <robin@icewind.nl>
Fri, 14 Oct 2022 14:28:49 +0000 (16:28 +0200)
Signed-off-by: Robin Appelman <robin@icewind.nl>
remote.php

index 69e3a53eeece7a5ba354d04f2ce5621e5782f0ce..5254b2b7419098f936e345025349d9392c60c28f 100644 (file)
@@ -49,42 +49,46 @@ class RemoteException extends Exception {
  * @param Exception|Error $e
  */
 function handleException($e) {
-       $request = \OC::$server->getRequest();
-       // in case the request content type is text/xml - we assume it's a WebDAV request
-       $isXmlContentType = strpos($request->getHeader('Content-Type'), 'text/xml');
-       if ($isXmlContentType === 0) {
-               // fire up a simple server to properly process the exception
-               $server = new Server();
-               if (!($e instanceof RemoteException)) {
-                       // we shall not log on RemoteException
-                       $server->addPlugin(new ExceptionLoggerPlugin('webdav', \OC::$server->getLogger()));
-               }
-               $server->on('beforeMethod:*', function () use ($e) {
-                       if ($e instanceof RemoteException) {
-                               switch ($e->getCode()) {
-                                       case 503:
-                                               throw new ServiceUnavailable($e->getMessage());
-                                       case 404:
-                                               throw new \Sabre\DAV\Exception\NotFound($e->getMessage());
-                               }
+       try {
+               $request = \OC::$server->getRequest();
+               // in case the request content type is text/xml - we assume it's a WebDAV request
+               $isXmlContentType = strpos($request->getHeader('Content-Type'), 'text/xml');
+               if ($isXmlContentType === 0) {
+                       // fire up a simple server to properly process the exception
+                       $server = new Server();
+                       if (!($e instanceof RemoteException)) {
+                               // we shall not log on RemoteException
+                               $server->addPlugin(new ExceptionLoggerPlugin('webdav', \OC::$server->getLogger()));
                        }
-                       $class = get_class($e);
-                       $msg = $e->getMessage();
-                       throw new ServiceUnavailable("$class: $msg");
-               });
-               $server->exec();
-       } else {
-               $statusCode = 500;
-               if ($e instanceof \OC\ServiceUnavailableException) {
-                       $statusCode = 503;
-               }
-               if ($e instanceof RemoteException) {
-                       // we shall not log on RemoteException
-                       OC_Template::printErrorPage($e->getMessage(), '', $e->getCode());
+                       $server->on('beforeMethod:*', function () use ($e) {
+                               if ($e instanceof RemoteException) {
+                                       switch ($e->getCode()) {
+                                               case 503:
+                                                       throw new ServiceUnavailable($e->getMessage());
+                                               case 404:
+                                                       throw new \Sabre\DAV\Exception\NotFound($e->getMessage());
+                                       }
+                               }
+                               $class = get_class($e);
+                               $msg = $e->getMessage();
+                               throw new ServiceUnavailable("$class: $msg");
+                       });
+                       $server->exec();
                } else {
-                       \OC::$server->getLogger()->logException($e, ['app' => 'remote']);
-                       OC_Template::printExceptionErrorPage($e, $statusCode);
+                       $statusCode = 500;
+                       if ($e instanceof \OC\ServiceUnavailableException) {
+                               $statusCode = 503;
+                       }
+                       if ($e instanceof RemoteException) {
+                               // we shall not log on RemoteException
+                               OC_Template::printErrorPage($e->getMessage(), '', $e->getCode());
+                       } else {
+                               \OC::$server->getLogger()->logException($e, ['app' => 'remote']);
+                               OC_Template::printExceptionErrorPage($e, $statusCode);
+                       }
                }
+       } catch (\Exception $e) {
+               OC_Template::printExceptionErrorPage($e, 500);
        }
 }