1
0
Fork 0
mirror of synced 2024-06-17 10:14:50 +12:00

feat: update error codes in the health API

This commit is contained in:
Christy Jacob 2022-02-06 21:21:47 +04:00
parent 78a4091f62
commit 53807ab47c
2 changed files with 15 additions and 8 deletions

View file

@ -2,7 +2,7 @@
use Appwrite\Utopia\Response;
use Utopia\App;
use Utopia\Exception;
use Appwrite\Extend\Exception;
use Utopia\Storage\Device\Local;
use Utopia\Storage\Storage;
use Appwrite\ClamAV\Network;
@ -75,7 +75,7 @@ App::get('/v1/health/db')
$statement->execute();
} catch (Exception $_e) {
throw new Exception('Database is not available', 500);
throw new Exception('Database is not available', 500, Exception::DATABASE_NOT_AVAILABLE);
}
$output = [
@ -109,7 +109,7 @@ App::get('/v1/health/cache')
$redis = $utopia->getResource('cache');
if (!$redis->ping(true)) {
throw new Exception('Cache is not available', 500);
throw new Exception('Cache is not available', 500, Exception::CACHE_NOT_AVAILABLE);
}
$output = [
@ -166,7 +166,7 @@ App::get('/v1/health/time')
$diff = ($timestamp - \time());
if ($diff > $gap || $diff < ($gap * -1)) {
throw new Exception('Server time gaps detected');
throw new Exception('Server time gaps detected', 500, Exception::TIME_GAPS_DETECTED);
}
$output = [
@ -294,11 +294,11 @@ App::get('/v1/health/storage/local')
$device = new Local($volume);
if (!\is_readable($device->getRoot())) {
throw new Exception('Device '.$key.' dir is not readable');
throw new Exception('Device '.$key.' dir is not readable', 500, Exception::STORAGE_NOT_READABLE);
}
if (!\is_writable($device->getRoot())) {
throw new Exception('Device '.$key.' dir is not writable');
throw new Exception('Device '.$key.' dir is not writable', 500, Exception::STORAGE_NOT_WRITABLE);
}
}
@ -341,7 +341,7 @@ App::get('/v1/health/anti-virus')
$output['version'] = @$antivirus->version();
$output['status'] = (@$antivirus->ping()) ? 'pass' : 'fail';
} catch( \Exception $e) {
throw new Exception('Antivirus is not available', 500);
throw new Exception('Antivirus is not available', 500, Exception::ANTIVIRUS_NOT_AVAILABLE);
}
}

View file

@ -75,6 +75,7 @@ class Exception extends \Exception
const AVATAR_ICON_NOT_FOUND = 'avatar_icon_not_found';
/** Storage */
const STORAGE_ERROR = 'storage_error';
const STORAGE_FILE_NOT_FOUND = 'storage_file_not_found';
const STORAGE_DEVICE_NOT_FOUND = 'storage_device_not_found';
const STORAGE_FILE_DELETION_FAILED = 'storage_file_deletion_failed';
@ -155,9 +156,15 @@ class Exception extends \Exception
const INVALID_READ_PERMISSIONS = 'invalid_read_permissions';
const INVALID_WRITE_PERMISSIONS = 'invalid_write_permissions';
const UNAUTHORIZED_SCOPE = 'unauthorized_scope';
const STORAGE_ERROR = 'storage_error';
const RATE_LIMIT_EXCEEDED = 'rate_limit_exceeded';
const SMTP_DISABLED = 'smtp_disabled';
const DATABASE_NOT_AVAILABLE = 'database_not_available';
const CACHE_NOT_AVAILABLE = 'cache_not_available';
const TIME_GAPS_DETECTED = 'time_gaps_detected';
const STORAGE_NOT_READABLE = 'storage_not_readable';
const STORAGE_NOT_WRITABLE = 'storage_not_writable';
const ANTIVIRUS_NOT_AVAILABLE = 'antivirus_not_available';
private $errorCode = '';