feat: add type attribute to returned error
This commit is contained in:
parent
c861d3c52f
commit
847abadd39
|
@ -8,6 +8,16 @@ use Appwrite\Extend\Exception;
|
|||
|
||||
return [
|
||||
/** General Errors */
|
||||
Exception::GENERAL_DEFAULT => [
|
||||
'name' => Exception::GENERAL_DEFAULT,
|
||||
'description' => 'Default error',
|
||||
'code' => 500,
|
||||
],
|
||||
Exception::GENERAL_ACCESS_FORBIDDEN => [
|
||||
'name' => Exception::GENERAL_ACCESS_FORBIDDEN,
|
||||
'description' => 'Access forbidden',
|
||||
'code' => 403,
|
||||
],
|
||||
Exception::GENERAL_UNKNOWN_ORIGIN => [
|
||||
'name' => Exception::GENERAL_UNKNOWN_ORIGIN,
|
||||
'description' => 'The request originated from a non-whitelisted origin. If you trust this origin, please add it as a platform in the Appwrite console.',
|
||||
|
@ -30,9 +40,14 @@ return [
|
|||
],
|
||||
Exception::GENERAL_SMTP_DISABLED => [
|
||||
'name' => Exception::GENERAL_SMTP_DISABLED,
|
||||
'description' => 'SMTP is disabled on your Appwrite instance. Please contact your project ',
|
||||
'description' => 'SMTP is disabled on your Appwrite instance. Please contact your project.',
|
||||
'code' => 503,
|
||||
],
|
||||
Exception::GENERAL_SERVER_ERROR => [
|
||||
'name' => Exception::GENERAL_SERVER_ERROR,
|
||||
'description' => 'Internal server error.',
|
||||
'code' => 500,
|
||||
],
|
||||
|
||||
/** Project Errors */
|
||||
Exception::PROJECT_NOT_FOUND => [
|
||||
|
|
|
@ -431,10 +431,12 @@ App::error(function ($error, $utopia, $request, $response, $layout, $project, $l
|
|||
'line' => $error->getLine(),
|
||||
'trace' => $error->getTrace(),
|
||||
'version' => $version,
|
||||
'type' => $error->getType(),
|
||||
] : [
|
||||
'message' => $message,
|
||||
'code' => $code,
|
||||
'version' => $version,
|
||||
'type' => $error->getType(),
|
||||
];
|
||||
|
||||
$response
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
|
||||
namespace Appwrite\Extend;
|
||||
|
||||
use Utopia\Config\Config;
|
||||
|
||||
class Exception extends \Exception
|
||||
{
|
||||
/**
|
||||
|
@ -156,11 +154,11 @@ class Exception extends \Exception
|
|||
const GENERAL_SERVER_ERROR = 'general_server_error';
|
||||
|
||||
|
||||
private $errorCode = '';
|
||||
private $type = '';
|
||||
|
||||
public function __construct(string $message, int $code = 0, string $errorCode = Exception::GENERAL_DEFAULT, \Throwable $previous = null)
|
||||
public function __construct(string $message, int $code = 0, string $type = Exception::GENERAL_DEFAULT, \Throwable $previous = null)
|
||||
{
|
||||
$this->errorCode = $errorCode;
|
||||
$this->type = $type;
|
||||
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
|
@ -168,8 +166,8 @@ class Exception extends \Exception
|
|||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getErrorCode(): string
|
||||
public function getType(): string
|
||||
{
|
||||
return $this->errorCode;
|
||||
return $this->type;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue