feat: load error codes in exception
This commit is contained in:
parent
9f671cfb18
commit
785af114f0
|
@ -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');
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue