Do not use HTTP code OC_Response constants anymore
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
This commit is contained in:
parent
79d9841bce
commit
b0a296e2e1
5 changed files with 16 additions and 26 deletions
|
@ -45,10 +45,10 @@ try {
|
||||||
\OC::$server->getLogger()->logException($ex, array('app' => 'index'));
|
\OC::$server->getLogger()->logException($ex, array('app' => 'index'));
|
||||||
|
|
||||||
//show the user a detailed error page
|
//show the user a detailed error page
|
||||||
OC_Template::printExceptionErrorPage($ex, \OC_Response::STATUS_SERVICE_UNAVAILABLE);
|
OC_Template::printExceptionErrorPage($ex, 503);
|
||||||
} catch (\OC\HintException $ex) {
|
} catch (\OC\HintException $ex) {
|
||||||
try {
|
try {
|
||||||
OC_Template::printErrorPage($ex->getMessage(), $ex->getHint(), OC_Response::STATUS_SERVICE_UNAVAILABLE);
|
OC_Template::printErrorPage($ex->getMessage(), $ex->getHint(), 503);
|
||||||
} catch (Exception $ex2) {
|
} catch (Exception $ex2) {
|
||||||
\OC::$server->getLogger()->logException($ex, array('app' => 'index'));
|
\OC::$server->getLogger()->logException($ex, array('app' => 'index'));
|
||||||
\OC::$server->getLogger()->logException($ex2, array('app' => 'index'));
|
\OC::$server->getLogger()->logException($ex2, array('app' => 'index'));
|
||||||
|
@ -57,7 +57,7 @@ try {
|
||||||
OC_Template::printExceptionErrorPage($ex, 500);
|
OC_Template::printExceptionErrorPage($ex, 500);
|
||||||
}
|
}
|
||||||
} catch (\OC\User\LoginException $ex) {
|
} catch (\OC\User\LoginException $ex) {
|
||||||
OC_Template::printErrorPage($ex->getMessage(), $ex->getMessage(), OC_Response::STATUS_FORBIDDEN);
|
OC_Template::printErrorPage($ex->getMessage(), $ex->getMessage(), 403);
|
||||||
} catch (Exception $ex) {
|
} catch (Exception $ex) {
|
||||||
\OC::$server->getLogger()->logException($ex, array('app' => 'index'));
|
\OC::$server->getLogger()->logException($ex, array('app' => 'index'));
|
||||||
|
|
||||||
|
@ -76,5 +76,5 @@ try {
|
||||||
|
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
OC_Template::printExceptionErrorPage($ex, \OC_Response::STATUS_INTERNAL_SERVER_ERROR);
|
OC_Template::printExceptionErrorPage($ex, 500);
|
||||||
}
|
}
|
||||||
|
|
|
@ -432,7 +432,7 @@ class OC {
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
\OC::$server->getLogger()->logException($e, ['app' => 'base']);
|
\OC::$server->getLogger()->logException($e, ['app' => 'base']);
|
||||||
//show the user a detailed error page
|
//show the user a detailed error page
|
||||||
OC_Template::printExceptionErrorPage($e, \OC_Response::STATUS_INTERNAL_SERVER_ERROR);
|
OC_Template::printExceptionErrorPage($e, 500);
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,15 +31,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class OC_Response {
|
class OC_Response {
|
||||||
const STATUS_FOUND = 302;
|
|
||||||
const STATUS_NOT_MODIFIED = 304;
|
|
||||||
const STATUS_TEMPORARY_REDIRECT = 307;
|
|
||||||
const STATUS_BAD_REQUEST = 400;
|
|
||||||
const STATUS_FORBIDDEN = 403;
|
|
||||||
const STATUS_NOT_FOUND = 404;
|
|
||||||
const STATUS_INTERNAL_SERVER_ERROR = 500;
|
|
||||||
const STATUS_SERVICE_UNAVAILABLE = 503;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the content disposition header (with possible workarounds)
|
* Sets the content disposition header (with possible workarounds)
|
||||||
* @param string $filename file name
|
* @param string $filename file name
|
||||||
|
|
|
@ -36,7 +36,7 @@ try {
|
||||||
if (\OCP\Util::needUpgrade()) {
|
if (\OCP\Util::needUpgrade()) {
|
||||||
// since the behavior of apps or remotes are unpredictable during
|
// since the behavior of apps or remotes are unpredictable during
|
||||||
// an upgrade, return a 503 directly
|
// an upgrade, return a 503 directly
|
||||||
OC_Template::printErrorPage('Service unavailable', '', OC_Response::STATUS_SERVICE_UNAVAILABLE);
|
OC_Template::printErrorPage('Service unavailable', '', 503);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,10 +78,9 @@ try {
|
||||||
require_once OC_App::getAppPath($app) . '/' . $parts[1];
|
require_once OC_App::getAppPath($app) . '/' . $parts[1];
|
||||||
|
|
||||||
} catch (Exception $ex) {
|
} catch (Exception $ex) {
|
||||||
|
$status = 500;
|
||||||
if ($ex instanceof \OC\ServiceUnavailableException) {
|
if ($ex instanceof \OC\ServiceUnavailableException) {
|
||||||
$status = OC_Response::STATUS_SERVICE_UNAVAILABLE;
|
$status = 503;
|
||||||
} else {
|
|
||||||
$status = OC_Response::STATUS_INTERNAL_SERVER_ERROR;
|
|
||||||
}
|
}
|
||||||
//show the user a detailed error page
|
//show the user a detailed error page
|
||||||
\OC::$server->getLogger()->logException($ex, ['app' => 'public']);
|
\OC::$server->getLogger()->logException($ex, ['app' => 'public']);
|
||||||
|
@ -89,5 +88,5 @@ try {
|
||||||
} catch (Error $ex) {
|
} catch (Error $ex) {
|
||||||
//show the user a detailed error page
|
//show the user a detailed error page
|
||||||
\OC::$server->getLogger()->logException($ex, ['app' => 'public']);
|
\OC::$server->getLogger()->logException($ex, ['app' => 'public']);
|
||||||
OC_Template::printExceptionErrorPage($ex, OC_Response::STATUS_INTERNAL_SERVER_ERROR);
|
OC_Template::printExceptionErrorPage($ex, 500);
|
||||||
}
|
}
|
||||||
|
|
14
remote.php
14
remote.php
|
@ -59,9 +59,9 @@ function handleException($e) {
|
||||||
$server->on('beforeMethod', function () use ($e) {
|
$server->on('beforeMethod', function () use ($e) {
|
||||||
if ($e instanceof RemoteException) {
|
if ($e instanceof RemoteException) {
|
||||||
switch ($e->getCode()) {
|
switch ($e->getCode()) {
|
||||||
case OC_Response::STATUS_SERVICE_UNAVAILABLE:
|
case 503:
|
||||||
throw new ServiceUnavailable($e->getMessage());
|
throw new ServiceUnavailable($e->getMessage());
|
||||||
case OC_Response::STATUS_NOT_FOUND:
|
case 404:
|
||||||
throw new \Sabre\DAV\Exception\NotFound($e->getMessage());
|
throw new \Sabre\DAV\Exception\NotFound($e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,9 +71,9 @@ function handleException($e) {
|
||||||
});
|
});
|
||||||
$server->exec();
|
$server->exec();
|
||||||
} else {
|
} else {
|
||||||
$statusCode = OC_Response::STATUS_INTERNAL_SERVER_ERROR;
|
$statusCode = 500;
|
||||||
if ($e instanceof \OC\ServiceUnavailableException ) {
|
if ($e instanceof \OC\ServiceUnavailableException ) {
|
||||||
$statusCode = OC_Response::STATUS_SERVICE_UNAVAILABLE;
|
$statusCode = 503;
|
||||||
}
|
}
|
||||||
if ($e instanceof RemoteException) {
|
if ($e instanceof RemoteException) {
|
||||||
// we shall not log on RemoteException
|
// we shall not log on RemoteException
|
||||||
|
@ -118,13 +118,13 @@ try {
|
||||||
if (\OCP\Util::needUpgrade()) {
|
if (\OCP\Util::needUpgrade()) {
|
||||||
// since the behavior of apps or remotes are unpredictable during
|
// since the behavior of apps or remotes are unpredictable during
|
||||||
// an upgrade, return a 503 directly
|
// an upgrade, return a 503 directly
|
||||||
throw new RemoteException('Service unavailable', OC_Response::STATUS_SERVICE_UNAVAILABLE);
|
throw new RemoteException('Service unavailable', 503);
|
||||||
}
|
}
|
||||||
|
|
||||||
$request = \OC::$server->getRequest();
|
$request = \OC::$server->getRequest();
|
||||||
$pathInfo = $request->getPathInfo();
|
$pathInfo = $request->getPathInfo();
|
||||||
if ($pathInfo === false || $pathInfo === '') {
|
if ($pathInfo === false || $pathInfo === '') {
|
||||||
throw new RemoteException('Path not found', OC_Response::STATUS_NOT_FOUND);
|
throw new RemoteException('Path not found', 404);
|
||||||
}
|
}
|
||||||
if (!$pos = strpos($pathInfo, '/', 1)) {
|
if (!$pos = strpos($pathInfo, '/', 1)) {
|
||||||
$pos = strlen($pathInfo);
|
$pos = strlen($pathInfo);
|
||||||
|
@ -134,7 +134,7 @@ try {
|
||||||
$file = resolveService($service);
|
$file = resolveService($service);
|
||||||
|
|
||||||
if(is_null($file)) {
|
if(is_null($file)) {
|
||||||
throw new RemoteException('Path not found', OC_Response::STATUS_NOT_FOUND);
|
throw new RemoteException('Path not found', 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
$file=ltrim($file, '/');
|
$file=ltrim($file, '/');
|
||||||
|
|
Loading…
Reference in a new issue