Skip to content
Snippets Groups Projects

7821 improve api error messages

Merged Hahn Axel (hahn) requested to merge 7821-improve-api-error-messages into master
2 files
+ 75
66
Compare changes
  • Side-by-side
  • Inline

Files

+ 11
6
@@ -68,6 +68,7 @@ function _quit(string $s, int $iStatus = 400): void
{
$aStatus = [
400 => 'HTTP/1.0 400 Bad Request',
401 => 'HTTP/1.0 401 Unauthorized',
403 => 'HTTP/1.0 403 Access denied',
404 => 'HTTP/1.0 404 Not found',
];
@@ -105,7 +106,7 @@ function _checkAuth(string $sProjectSecret): bool
$aReqHeaders = apache_request_headers();
_wd('<pre>' . print_r($aReqHeaders, 1) . '</pre>');
if (!isset($aReqHeaders['Authorization'])) {
_quit('Access denied. Missing authorization.', 403);
_quit('Access denied. Missing authorization.', 401);
}
if (!isset($aReqHeaders['Date'])) {
_quit('Access denied. Missing field "Date:" in the request header.', 403);
@@ -123,7 +124,7 @@ function _checkAuth(string $sProjectSecret): bool
_wd('Hash: ' . $sGotHash . ' -- from header');
_wd('Hash: ' . $sMyHash . ' -- rebuilt');
if ($sGotHash !== $sMyHash) {
_quit('Access denied. Invalid hash.', 403);
_quit('Access denied. Invalid hash.', 401);
}
$iAge = date('U') - date('U', strtotime($sGotDate));
@@ -216,14 +217,18 @@ switch ($sApiVersion) {
ob_end_clean();
} catch (Exception $exc) {
_quit('ERROR: project with id [' . $sPrjId . '] does not exist.', 404);
_quit('ERROR: project with id [' . $sPrjId . '] cannot be initialized.', 400); // never reached
}
// get secret
$aPrjCfg = $oProject->getConfig();
$sProjectSecret = isset($aPrjCfg['api']['secret']) ? $aPrjCfg['api']['secret'] : false;
if(!count($aPrjCfg)){
_quit('ERROR: project with id [' . $sPrjId . '] does not exist.', 404);
}
$sProjectSecret = $aPrjCfg['api']['secret'] ?? false;
if (!$sProjectSecret) {
_quit('Access denied. API access is disabled.');
_quit('Access denied. API access is disabled.', 403);
}
// check authorization
Loading