1
0
Fork 0
mirror of synced 2024-06-26 18:20:43 +12:00

feat: load error codes in exception

This commit is contained in:
Christy Jacob 2022-01-30 02:47:35 +04:00
parent 9f671cfb18
commit 785af114f0
2 changed files with 13 additions and 0 deletions

View file

@ -127,6 +127,7 @@ App::setMode(App::getEnv('_APP_ENV', App::MODE_TYPE_PRODUCTION));
*/
Config::load('events', __DIR__.'/config/events.php');
Config::load('auth', __DIR__.'/config/auth.php');
Config::load('errorCodes', __DIR__.'/config/errorCodes.php');
Config::load('providers', __DIR__.'/config/providers.php');
Config::load('platforms', __DIR__.'/config/platforms.php');
Config::load('collections', __DIR__.'/config/collections.php');

View file

@ -2,6 +2,8 @@
namespace Appwrite\Extend\Exception;
use Utopia\Config\Config;
class Exception extends \Exception
{
/**
@ -49,10 +51,20 @@ class Exception extends \Exception
private $errorCode = '';
static $codes = Config::getParam('errorCodes', []);
public function __construct(string $message, int $code = 0, string $errorCode = Exception::TYPE_NONE, \Throwable $previous = null)
{
if (!isset(self::$codes)) {
throw new \Exception('Error codes not found', 500);
}
$this->errorCode = $errorCode;
if (isset(self::$codes[$errorCode])) {
$this->$message = self::$codes[$errorCode]['statusCode'];
}
parent::__construct($message, $code, $previous);
}