Updated error when _APP_USAGE_STATS is disabled

for usage
This commit is contained in:
Bhaskar Singh
2023-03-18 22:03:15 +05:30
parent e8c74d7204
commit ac2085ffa8
8 changed files with 34 additions and 1 deletions
+5
View File
@@ -88,6 +88,11 @@ return [
'description' => 'The request cannot be fulfilled with the current protocol. Please check the value of the _APP_OPTIONS_FORCE_HTTPS environment variable.',
'code' => 500,
],
Exception::GENERAL_USAGE_DISABLED => [
'name' => Exception::GENERAL_USAGE_DISABLED,
'description' => 'Usage stats is not configured. Please check the value of the _APP_USAGE_STATS environment variable of your Appwrite server.',
'code' => 501,
],
/** User Errors */
Exception::USER_COUNT_EXCEEDED => [
+9
View File
@@ -2471,6 +2471,9 @@ App::get('/v1/databases/usage')
->action(function (string $range, Response $response, Database $dbForProject) {
$usage = [];
if (App::getEnv('_APP_USAGE_STATS', 'enabled') != 'enabled') {
throw new Exception(Exception::GENERAL_USAGE_DISABLED);
}
if (App::getEnv('_APP_USAGE_STATS', 'enabled') == 'enabled') {
$periods = [
'24h' => [
@@ -2590,6 +2593,9 @@ App::get('/v1/databases/:databaseId/usage')
->action(function (string $databaseId, string $range, Response $response, Database $dbForProject) {
$usage = [];
if (App::getEnv('_APP_USAGE_STATS', 'enabled') != 'enabled') {
throw new Exception(Exception::GENERAL_USAGE_DISABLED);
}
if (App::getEnv('_APP_USAGE_STATS', 'enabled') == 'enabled') {
$periods = [
'24h' => [
@@ -2710,6 +2716,9 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/usage')
}
$usage = [];
if (App::getEnv('_APP_USAGE_STATS', 'enabled') != 'enabled') {
throw new Exception(Exception::GENERAL_USAGE_DISABLED);
}
if (App::getEnv('_APP_USAGE_STATS', 'enabled') == 'enabled') {
$periods = [
'24h' => [
+6
View File
@@ -234,6 +234,9 @@ App::get('/v1/functions/:functionId/usage')
}
$usage = [];
if (App::getEnv('_APP_USAGE_STATS', 'enabled') != 'enabled') {
throw new Exception(Exception::GENERAL_USAGE_DISABLED);
}
if (App::getEnv('_APP_USAGE_STATS', 'enabled') == 'enabled') {
$periods = [
'24h' => [
@@ -337,6 +340,9 @@ App::get('/v1/functions/usage')
->action(function (string $range, Response $response, Database $dbForProject) {
$usage = [];
if (App::getEnv('_APP_USAGE_STATS', 'enabled') != 'enabled') {
throw new Exception(Exception::GENERAL_USAGE_DISABLED);
}
if (App::getEnv('_APP_USAGE_STATS', 'enabled') == 'enabled') {
$periods = [
'24h' => [
+3
View File
@@ -268,6 +268,9 @@ App::get('/v1/projects/:projectId/usage')
}
$usage = [];
if (App::getEnv('_APP_USAGE_STATS', 'enabled') != 'enabled') {
throw new Exception(Exception::GENERAL_USAGE_DISABLED);
}
if (App::getEnv('_APP_USAGE_STATS', 'enabled') == 'enabled') {
$periods = [
'24h' => [
+6
View File
@@ -1461,6 +1461,9 @@ App::get('/v1/storage/usage')
->action(function (string $range, Response $response, Database $dbForProject) {
$usage = [];
if (App::getEnv('_APP_USAGE_STATS', 'enabled') != 'enabled') {
throw new Exception(Exception::GENERAL_USAGE_DISABLED);
}
if (App::getEnv('_APP_USAGE_STATS', 'enabled') === 'enabled') {
$periods = [
'24h' => [
@@ -1578,6 +1581,9 @@ App::get('/v1/storage/:bucketId/usage')
}
$usage = [];
if (App::getEnv('_APP_USAGE_STATS', 'enabled') != 'enabled') {
throw new Exception(Exception::GENERAL_USAGE_DISABLED);
}
if (App::getEnv('_APP_USAGE_STATS', 'enabled') === 'enabled') {
$periods = [
'24h' => [
+3
View File
@@ -1114,6 +1114,9 @@ App::get('/v1/users/usage')
->action(function (string $range, string $provider, Response $response, Database $dbForProject) {
$usage = [];
if (App::getEnv('_APP_USAGE_STATS', 'enabled') != 'enabled') {
throw new Exception(Exception::GENERAL_USAGE_DISABLED);
}
if (App::getEnv('_APP_USAGE_STATS', 'enabled') == 'enabled') {
$periods = [
'24h' => [
+1
View File
@@ -51,6 +51,7 @@ class Exception extends \Exception
public const GENERAL_CURSOR_NOT_FOUND = 'general_cursor_not_found';
public const GENERAL_SERVER_ERROR = 'general_server_error';
public const GENERAL_PROTOCOL_UNSUPPORTED = 'general_protocol_unsupported';
public const GENERAL_USAGE_DISABLED = 'general_usage_disabled';
/** Users */
public const USER_COUNT_EXCEEDED = 'user_count_exceeded';