return proper error code when reporting exception fails in remote.php
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
7d024bc337
commit
4dbcfa387a
70
remote.php
70
remote.php
|
@ -50,42 +50,46 @@ class RemoteException extends Exception {
|
||||||
* @param Exception|Error $e
|
* @param Exception|Error $e
|
||||||
*/
|
*/
|
||||||
function handleException($e) {
|
function handleException($e) {
|
||||||
$request = \OC::$server->getRequest();
|
try {
|
||||||
// in case the request content type is text/xml - we assume it's a WebDAV request
|
$request = \OC::$server->getRequest();
|
||||||
$isXmlContentType = strpos($request->getHeader('Content-Type'), 'text/xml');
|
// in case the request content type is text/xml - we assume it's a WebDAV request
|
||||||
if ($isXmlContentType === 0) {
|
$isXmlContentType = strpos($request->getHeader('Content-Type'), 'text/xml');
|
||||||
// fire up a simple server to properly process the exception
|
if ($isXmlContentType === 0) {
|
||||||
$server = new Server();
|
// fire up a simple server to properly process the exception
|
||||||
if (!($e instanceof RemoteException)) {
|
$server = new Server();
|
||||||
// we shall not log on RemoteException
|
if (!($e instanceof RemoteException)) {
|
||||||
$server->addPlugin(new ExceptionLoggerPlugin('webdav', \OC::$server->get(LoggerInterface::class)));
|
// 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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$class = get_class($e);
|
$server->on('beforeMethod:*', function () use ($e) {
|
||||||
$msg = $e->getMessage();
|
if ($e instanceof RemoteException) {
|
||||||
throw new ServiceUnavailable("$class: $msg");
|
switch ($e->getCode()) {
|
||||||
});
|
case 503:
|
||||||
$server->exec();
|
throw new ServiceUnavailable($e->getMessage());
|
||||||
} else {
|
case 404:
|
||||||
$statusCode = 500;
|
throw new \Sabre\DAV\Exception\NotFound($e->getMessage());
|
||||||
if ($e instanceof \OC\ServiceUnavailableException) {
|
}
|
||||||
$statusCode = 503;
|
}
|
||||||
}
|
$class = get_class($e);
|
||||||
if ($e instanceof RemoteException) {
|
$msg = $e->getMessage();
|
||||||
// we shall not log on RemoteException
|
throw new ServiceUnavailable("$class: $msg");
|
||||||
OC_Template::printErrorPage($e->getMessage(), '', $e->getCode());
|
});
|
||||||
|
$server->exec();
|
||||||
} else {
|
} else {
|
||||||
\OC::$server->get(LoggerInterface::class)->error($e->getMessage(), ['app' => 'remote','exception' => $e]);
|
$statusCode = 500;
|
||||||
OC_Template::printExceptionErrorPage($e, $statusCode);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue