From c34dc4dae0c9a7d3fa1c3123080fe748573b8812 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Thu, 16 Nov 2023 23:51:09 +0530 Subject: [PATCH 1/7] Add flag to send logs to logger --- app/config/errors.php | 9 +++++++++ app/controllers/api/health.php | 20 ++++++++++---------- app/controllers/general.php | 7 ++++++- src/Appwrite/Extend/Exception.php | 21 ++++++++++++++++++--- 4 files changed, 43 insertions(+), 14 deletions(-) diff --git a/app/config/errors.php b/app/config/errors.php index d18c7c2dc4..961cc3a197 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -209,6 +209,7 @@ return [ 'name' => Exception::USER_AUTH_METHOD_UNSUPPORTED, 'description' => 'The requested authentication method is either disabled or unsupported. Please check the supported authentication methods in the Appwrite console.', 'code' => 501, + 'log' => false, ], Exception::USER_PHONE_ALREADY_EXISTS => [ 'name' => Exception::USER_PHONE_ALREADY_EXISTS, @@ -764,4 +765,12 @@ return [ 'description' => 'An error occurred on the provider\'s side. Please try again later.', 'code' => 400, ], + + /** Health */ + Exception::QUEUE_SIZE_EXCEEDS => [ + 'name' => Exception::QUEUE_SIZE_EXCEEDS, + 'description' => 'Queue size threshold hit.', + 'code' => 503, + 'log' => false + ], ]; diff --git a/app/controllers/api/health.php b/app/controllers/api/health.php index 90e080d5fa..4db87befc2 100644 --- a/app/controllers/api/health.php +++ b/app/controllers/api/health.php @@ -355,7 +355,7 @@ App::get('/v1/health/queue/webhooks') $size = $client->getQueueSize(); if ($size >= $threshold) { - throw new Exception(Exception::GENERAL_SERVER_ERROR, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); + throw new Exception(Exception::QUEUE_SIZE_EXCEEDS, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); } $response->dynamic(new Document([ 'size' => $size ]), Response::MODEL_HEALTH_QUEUE); @@ -382,7 +382,7 @@ App::get('/v1/health/queue/logs') $size = $client->getQueueSize(); if ($size >= $threshold) { - throw new Exception(Exception::GENERAL_SERVER_ERROR, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); + throw new Exception(Exception::QUEUE_SIZE_EXCEEDS, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); } $response->dynamic(new Document([ 'size' => $size ]), Response::MODEL_HEALTH_QUEUE); @@ -409,7 +409,7 @@ App::get('/v1/health/queue/certificates') $size = $client->getQueueSize(); if ($size >= $threshold) { - throw new Exception(Exception::GENERAL_SERVER_ERROR, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); + throw new Exception(Exception::QUEUE_SIZE_EXCEEDS, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); } $response->dynamic(new Document([ 'size' => $size ]), Response::MODEL_HEALTH_QUEUE); @@ -436,7 +436,7 @@ App::get('/v1/health/queue/builds') $size = $client->getQueueSize(); if ($size >= $threshold) { - throw new Exception(Exception::GENERAL_SERVER_ERROR, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); + throw new Exception(Exception::QUEUE_SIZE_EXCEEDS, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); } $response->dynamic(new Document([ 'size' => $size ]), Response::MODEL_HEALTH_QUEUE); @@ -464,7 +464,7 @@ App::get('/v1/health/queue/databases') $size = $client->getQueueSize(); if ($size >= $threshold) { - throw new Exception(Exception::GENERAL_SERVER_ERROR, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); + throw new Exception(Exception::QUEUE_SIZE_EXCEEDS, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); } $response->dynamic(new Document([ 'size' => $size ]), Response::MODEL_HEALTH_QUEUE); @@ -491,7 +491,7 @@ App::get('/v1/health/queue/deletes') $size = $client->getQueueSize(); if ($size >= $threshold) { - throw new Exception(Exception::GENERAL_SERVER_ERROR, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); + throw new Exception(Exception::QUEUE_SIZE_EXCEEDS, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); } $response->dynamic(new Document([ 'size' => $size ]), Response::MODEL_HEALTH_QUEUE); @@ -518,7 +518,7 @@ App::get('/v1/health/queue/mails') $size = $client->getQueueSize(); if ($size >= $threshold) { - throw new Exception(Exception::GENERAL_SERVER_ERROR, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); + throw new Exception(Exception::QUEUE_SIZE_EXCEEDS, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); } $response->dynamic(new Document([ 'size' => $size ]), Response::MODEL_HEALTH_QUEUE); @@ -545,7 +545,7 @@ App::get('/v1/health/queue/messaging') $size = $client->getQueueSize(); if ($size >= $threshold) { - throw new Exception(Exception::GENERAL_SERVER_ERROR, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); + throw new Exception(Exception::QUEUE_SIZE_EXCEEDS, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); } $response->dynamic(new Document([ 'size' => $size ]), Response::MODEL_HEALTH_QUEUE); @@ -572,7 +572,7 @@ App::get('/v1/health/queue/migrations') $size = $client->getQueueSize(); if ($size >= $threshold) { - throw new Exception(Exception::GENERAL_SERVER_ERROR, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); + throw new Exception(Exception::QUEUE_SIZE_EXCEEDS, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); } $response->dynamic(new Document([ 'size' => $size ]), Response::MODEL_HEALTH_QUEUE); @@ -599,7 +599,7 @@ App::get('/v1/health/queue/functions') $size = $client->getQueueSize(); if ($size >= $threshold) { - throw new Exception(Exception::GENERAL_SERVER_ERROR, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); + throw new Exception(Exception::QUEUE_SIZE_EXCEEDS, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); } $response->dynamic(new Document([ 'size' => $size ]), Response::MODEL_HEALTH_QUEUE); diff --git a/app/controllers/general.php b/app/controllers/general.php index cf383b6710..a7f3223031 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -608,9 +608,14 @@ App::error() $version = App::getEnv('_APP_VERSION', 'UNKNOWN'); $route = $utopia->getRoute(); + $publishLog = true; + + if ($error instanceof AppwriteException) { + $publishLog = $error->getLog(); + } if ($logger) { - if ($error->getCode() >= 500 || $error->getCode() === 0) { + if (($error->getCode() >= 500 || $error->getCode() === 0) && $publishLog) { try { /** @var Utopia\Database\Document $user */ $user = $utopia->getResource('user'); diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index 5727a0ed11..a01705f15e 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -229,12 +229,16 @@ class Exception extends \Exception public const MIGRATION_PROVIDER_ERROR = 'migration_provider_error'; /** Realtime */ - public const REALTIME_MESSAGE_FORMAT_INVALID = 'realtime_message_format_invalid'; - public const REALTIME_TOO_MANY_MESSAGES = 'realtime_too_many_messages'; - public const REALTIME_POLICY_VIOLATION = 'realtime_policy_violation'; + public const REALTIME_MESSAGE_FORMAT_INVALID = 'realtime_message_format_invalid'; + public const REALTIME_TOO_MANY_MESSAGES = 'realtime_too_many_messages'; + public const REALTIME_POLICY_VIOLATION = 'realtime_policy_violation'; + + /** Health */ + public const QUEUE_SIZE_EXCEEDS = 'queue_size_exceeds'; protected string $type = ''; protected array $errors = []; + protected bool $log = true; public function __construct(string $type = Exception::GENERAL_UNKNOWN, string $message = null, int $code = null, \Throwable $previous = null) { @@ -244,6 +248,7 @@ class Exception extends \Exception if (isset($this->errors[$type])) { $this->code = $this->errors[$type]['code']; $this->message = $this->errors[$type]['description']; + $this->log = $this->errors[$type]['log'] ?? true; } $this->message = $message ?? $this->message; @@ -273,4 +278,14 @@ class Exception extends \Exception { $this->type = $type; } + + /** + * Get the log of the exception. + * + * @return bool + */ + public function getLog(): bool + { + return $this->log; + } } From 881b92eeb810b0d54e223b7cfcf9085e4f486645 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Fri, 17 Nov 2023 00:19:43 +0530 Subject: [PATCH 2/7] Updated error codes in health tests --- .../Health/HealthCustomServerTest.php | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/e2e/Services/Health/HealthCustomServerTest.php b/tests/e2e/Services/Health/HealthCustomServerTest.php index 8fa9faadd2..3ea1b884a7 100644 --- a/tests/e2e/Services/Health/HealthCustomServerTest.php +++ b/tests/e2e/Services/Health/HealthCustomServerTest.php @@ -145,7 +145,7 @@ class HealthCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); - $this->assertEquals(500, $response['headers']['status-code']); + $this->assertEquals(503, $response['headers']['status-code']); return []; } @@ -171,7 +171,7 @@ class HealthCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); - $this->assertEquals(500, $response['headers']['status-code']); + $this->assertEquals(503, $response['headers']['status-code']); return []; } @@ -197,7 +197,7 @@ class HealthCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); - $this->assertEquals(500, $response['headers']['status-code']); + $this->assertEquals(503, $response['headers']['status-code']); return []; } @@ -223,7 +223,7 @@ class HealthCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); - $this->assertEquals(500, $response['headers']['status-code']); + $this->assertEquals(503, $response['headers']['status-code']); return []; } @@ -249,7 +249,7 @@ class HealthCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); - $this->assertEquals(500, $response['headers']['status-code']); + $this->assertEquals(503, $response['headers']['status-code']); return []; } @@ -280,7 +280,7 @@ class HealthCustomServerTest extends Scope 'name' => 'database_db_main', 'threshold' => '0' ]); - $this->assertEquals(500, $response['headers']['status-code']); + $this->assertEquals(503, $response['headers']['status-code']); return []; } @@ -306,7 +306,7 @@ class HealthCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); - $this->assertEquals(500, $response['headers']['status-code']); + $this->assertEquals(503, $response['headers']['status-code']); return []; } @@ -332,7 +332,7 @@ class HealthCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); - $this->assertEquals(500, $response['headers']['status-code']); + $this->assertEquals(503, $response['headers']['status-code']); return []; } @@ -358,7 +358,7 @@ class HealthCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); - $this->assertEquals(500, $response['headers']['status-code']); + $this->assertEquals(503, $response['headers']['status-code']); return []; } @@ -384,7 +384,7 @@ class HealthCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); - $this->assertEquals(500, $response['headers']['status-code']); + $this->assertEquals(503, $response['headers']['status-code']); return []; } From 40ec98569e74288c72ab5e31b1d91b0c97432f2d Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Fri, 17 Nov 2023 18:35:26 +0530 Subject: [PATCH 3/7] Update app/controllers/general.php Co-authored-by: Christy Jacob --- app/controllers/general.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index a7f3223031..f086ccd26f 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -614,7 +614,7 @@ App::error() $publishLog = $error->getLog(); } - if ($logger) { + if ($logger && publish) { if (($error->getCode() >= 500 || $error->getCode() === 0) && $publishLog) { try { /** @var Utopia\Database\Document $user */ From 93292879821e52b4aa25c8687fc1832fcc62958d Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Fri, 17 Nov 2023 18:35:51 +0530 Subject: [PATCH 4/7] Update app/controllers/general.php Co-authored-by: Christy Jacob --- app/controllers/general.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index f086ccd26f..ae6a003a17 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -608,7 +608,7 @@ App::error() $version = App::getEnv('_APP_VERSION', 'UNKNOWN'); $route = $utopia->getRoute(); - $publishLog = true; + $publish = true; if ($error instanceof AppwriteException) { $publishLog = $error->getLog(); From cf1c914edb901454f4eeb0336baa967b7cffb136 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Fri, 17 Nov 2023 18:36:03 +0530 Subject: [PATCH 5/7] Update app/controllers/general.php Co-authored-by: Christy Jacob --- app/controllers/general.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index ae6a003a17..bda54eda92 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -615,7 +615,7 @@ App::error() } if ($logger && publish) { - if (($error->getCode() >= 500 || $error->getCode() === 0) && $publishLog) { + if ($error->getCode() >= 500 || $error->getCode() === 0) { try { /** @var Utopia\Database\Document $user */ $user = $utopia->getResource('user'); From 7902defe69383d04a6724b3fd76b2e70de8a90d1 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Fri, 17 Nov 2023 19:29:57 +0530 Subject: [PATCH 6/7] Addressed PR comments --- app/config/errors.php | 8 ++++---- app/controllers/api/health.php | 20 ++++++++++---------- app/controllers/general.php | 4 ++-- src/Appwrite/Extend/Exception.php | 12 ++++++------ 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/app/config/errors.php b/app/config/errors.php index 961cc3a197..bbedf0f24b 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -209,7 +209,7 @@ return [ 'name' => Exception::USER_AUTH_METHOD_UNSUPPORTED, 'description' => 'The requested authentication method is either disabled or unsupported. Please check the supported authentication methods in the Appwrite console.', 'code' => 501, - 'log' => false, + 'publishLog' => false, ], Exception::USER_PHONE_ALREADY_EXISTS => [ 'name' => Exception::USER_PHONE_ALREADY_EXISTS, @@ -767,10 +767,10 @@ return [ ], /** Health */ - Exception::QUEUE_SIZE_EXCEEDS => [ - 'name' => Exception::QUEUE_SIZE_EXCEEDS, + Exception::QUEUE_SIZE_EXCEEDED => [ + 'name' => Exception::QUEUE_SIZE_EXCEEDED, 'description' => 'Queue size threshold hit.', 'code' => 503, - 'log' => false + 'publishLog' => false ], ]; diff --git a/app/controllers/api/health.php b/app/controllers/api/health.php index 4db87befc2..4f459dd862 100644 --- a/app/controllers/api/health.php +++ b/app/controllers/api/health.php @@ -355,7 +355,7 @@ App::get('/v1/health/queue/webhooks') $size = $client->getQueueSize(); if ($size >= $threshold) { - throw new Exception(Exception::QUEUE_SIZE_EXCEEDS, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); + throw new Exception(Exception::QUEUE_SIZE_EXCEEDED, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); } $response->dynamic(new Document([ 'size' => $size ]), Response::MODEL_HEALTH_QUEUE); @@ -382,7 +382,7 @@ App::get('/v1/health/queue/logs') $size = $client->getQueueSize(); if ($size >= $threshold) { - throw new Exception(Exception::QUEUE_SIZE_EXCEEDS, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); + throw new Exception(Exception::QUEUE_SIZE_EXCEEDED, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); } $response->dynamic(new Document([ 'size' => $size ]), Response::MODEL_HEALTH_QUEUE); @@ -409,7 +409,7 @@ App::get('/v1/health/queue/certificates') $size = $client->getQueueSize(); if ($size >= $threshold) { - throw new Exception(Exception::QUEUE_SIZE_EXCEEDS, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); + throw new Exception(Exception::QUEUE_SIZE_EXCEEDED, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); } $response->dynamic(new Document([ 'size' => $size ]), Response::MODEL_HEALTH_QUEUE); @@ -436,7 +436,7 @@ App::get('/v1/health/queue/builds') $size = $client->getQueueSize(); if ($size >= $threshold) { - throw new Exception(Exception::QUEUE_SIZE_EXCEEDS, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); + throw new Exception(Exception::QUEUE_SIZE_EXCEEDED, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); } $response->dynamic(new Document([ 'size' => $size ]), Response::MODEL_HEALTH_QUEUE); @@ -464,7 +464,7 @@ App::get('/v1/health/queue/databases') $size = $client->getQueueSize(); if ($size >= $threshold) { - throw new Exception(Exception::QUEUE_SIZE_EXCEEDS, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); + throw new Exception(Exception::QUEUE_SIZE_EXCEEDED, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); } $response->dynamic(new Document([ 'size' => $size ]), Response::MODEL_HEALTH_QUEUE); @@ -491,7 +491,7 @@ App::get('/v1/health/queue/deletes') $size = $client->getQueueSize(); if ($size >= $threshold) { - throw new Exception(Exception::QUEUE_SIZE_EXCEEDS, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); + throw new Exception(Exception::QUEUE_SIZE_EXCEEDED, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); } $response->dynamic(new Document([ 'size' => $size ]), Response::MODEL_HEALTH_QUEUE); @@ -518,7 +518,7 @@ App::get('/v1/health/queue/mails') $size = $client->getQueueSize(); if ($size >= $threshold) { - throw new Exception(Exception::QUEUE_SIZE_EXCEEDS, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); + throw new Exception(Exception::QUEUE_SIZE_EXCEEDED, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); } $response->dynamic(new Document([ 'size' => $size ]), Response::MODEL_HEALTH_QUEUE); @@ -545,7 +545,7 @@ App::get('/v1/health/queue/messaging') $size = $client->getQueueSize(); if ($size >= $threshold) { - throw new Exception(Exception::QUEUE_SIZE_EXCEEDS, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); + throw new Exception(Exception::QUEUE_SIZE_EXCEEDED, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); } $response->dynamic(new Document([ 'size' => $size ]), Response::MODEL_HEALTH_QUEUE); @@ -572,7 +572,7 @@ App::get('/v1/health/queue/migrations') $size = $client->getQueueSize(); if ($size >= $threshold) { - throw new Exception(Exception::QUEUE_SIZE_EXCEEDS, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); + throw new Exception(Exception::QUEUE_SIZE_EXCEEDED, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); } $response->dynamic(new Document([ 'size' => $size ]), Response::MODEL_HEALTH_QUEUE); @@ -599,7 +599,7 @@ App::get('/v1/health/queue/functions') $size = $client->getQueueSize(); if ($size >= $threshold) { - throw new Exception(Exception::QUEUE_SIZE_EXCEEDS, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); + throw new Exception(Exception::QUEUE_SIZE_EXCEEDED, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}."); } $response->dynamic(new Document([ 'size' => $size ]), Response::MODEL_HEALTH_QUEUE); diff --git a/app/controllers/general.php b/app/controllers/general.php index bda54eda92..72138acea0 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -611,10 +611,10 @@ App::error() $publish = true; if ($error instanceof AppwriteException) { - $publishLog = $error->getLog(); + $publish = $error->getPublishLog(); } - if ($logger && publish) { + if ($logger && $publish) { if ($error->getCode() >= 500 || $error->getCode() === 0) { try { /** @var Utopia\Database\Document $user */ diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index a01705f15e..c63555262a 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -234,11 +234,11 @@ class Exception extends \Exception public const REALTIME_POLICY_VIOLATION = 'realtime_policy_violation'; /** Health */ - public const QUEUE_SIZE_EXCEEDS = 'queue_size_exceeds'; + public const QUEUE_SIZE_EXCEEDED = 'queue_size_exceeded'; protected string $type = ''; protected array $errors = []; - protected bool $log = true; + protected bool $publishLog = true; public function __construct(string $type = Exception::GENERAL_UNKNOWN, string $message = null, int $code = null, \Throwable $previous = null) { @@ -248,7 +248,7 @@ class Exception extends \Exception if (isset($this->errors[$type])) { $this->code = $this->errors[$type]['code']; $this->message = $this->errors[$type]['description']; - $this->log = $this->errors[$type]['log'] ?? true; + $this->publishLog = $this->errors[$type]['publishLog'] ?? true; } $this->message = $message ?? $this->message; @@ -280,12 +280,12 @@ class Exception extends \Exception } /** - * Get the log of the exception. + * Get the value of publishLog for the exception. * * @return bool */ - public function getLog(): bool + public function getPublishLog(): bool { - return $this->log; + return $this->publishLog; } } From 695d6f4065f412719910b1a5c9b657f99a75011c Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Sat, 18 Nov 2023 00:04:57 +0530 Subject: [PATCH 7/7] Renamed variables --- app/config/errors.php | 4 ++-- app/controllers/general.php | 2 +- src/Appwrite/Extend/Exception.php | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/config/errors.php b/app/config/errors.php index bbedf0f24b..c0628920d9 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -209,7 +209,7 @@ return [ 'name' => Exception::USER_AUTH_METHOD_UNSUPPORTED, 'description' => 'The requested authentication method is either disabled or unsupported. Please check the supported authentication methods in the Appwrite console.', 'code' => 501, - 'publishLog' => false, + 'publish' => false, ], Exception::USER_PHONE_ALREADY_EXISTS => [ 'name' => Exception::USER_PHONE_ALREADY_EXISTS, @@ -771,6 +771,6 @@ return [ 'name' => Exception::QUEUE_SIZE_EXCEEDED, 'description' => 'Queue size threshold hit.', 'code' => 503, - 'publishLog' => false + 'publish' => false ], ]; diff --git a/app/controllers/general.php b/app/controllers/general.php index 72138acea0..e443b96fc9 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -611,7 +611,7 @@ App::error() $publish = true; if ($error instanceof AppwriteException) { - $publish = $error->getPublishLog(); + $publish = $error->isPublishable(); } if ($logger && $publish) { diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index c63555262a..6449ffd93a 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -238,7 +238,7 @@ class Exception extends \Exception protected string $type = ''; protected array $errors = []; - protected bool $publishLog = true; + protected bool $publish = true; public function __construct(string $type = Exception::GENERAL_UNKNOWN, string $message = null, int $code = null, \Throwable $previous = null) { @@ -248,7 +248,7 @@ class Exception extends \Exception if (isset($this->errors[$type])) { $this->code = $this->errors[$type]['code']; $this->message = $this->errors[$type]['description']; - $this->publishLog = $this->errors[$type]['publishLog'] ?? true; + $this->publish = $this->errors[$type]['publish'] ?? true; } $this->message = $message ?? $this->message; @@ -280,12 +280,12 @@ class Exception extends \Exception } /** - * Get the value of publishLog for the exception. + * Check whether the log is publishable for the exception. * * @return bool */ - public function getPublishLog(): bool + public function isPublishable(): bool { - return $this->publishLog; + return $this->publish; } }