Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Petry <vincent@nextcloud.com>2022-10-27 11:26:08 +0300
committerGitHub <noreply@github.com>2022-10-27 11:26:08 +0300
commit4a448f31b25420e5bb005e619fdb8d602d78a8f0 (patch)
tree23bbb7bb7a4bcc256a838b83733b1e2f55f3a297
parent62e5313cdaabe79caf2a4decde206727e0405737 (diff)
parentb695d2f107b98a65dc41a9ce48e67c26b7f48bd6 (diff)
Merge pull request #34581 from nextcloud/backport/34438/stable25
[stable25] return proper error code when reporting exception fails in remote.php
-rw-r--r--remote.php70
1 files changed, 37 insertions, 33 deletions
diff --git a/remote.php b/remote.php
index 95855fea6ab..43376424af8 100644
--- a/remote.php
+++ b/remote.php
@@ -50,42 +50,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->get(LoggerInterface::class)));
- }
- $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->get(LoggerInterface::class)));
}
- $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->get(LoggerInterface::class)->error($e->getMessage(), ['app' => 'remote','exception' => $e]);
- 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->get(LoggerInterface::class)->error($e->getMessage(), ['app' => 'remote','exception' => $e]);
+ OC_Template::printExceptionErrorPage($e, $statusCode);
+ }
}
+ } catch (\Exception $e) {
+ OC_Template::printExceptionErrorPage($e, 500);
}
}