diff --git a/src/Exceptions/ConnectionWrongData.php b/src/Exceptions/ConnectionWrongData.php index 6c83598..a745053 100644 --- a/src/Exceptions/ConnectionWrongData.php +++ b/src/Exceptions/ConnectionWrongData.php @@ -6,8 +6,8 @@ class ConnectionWrongData extends Exception { - public function __construct(string $message = '', Throwable $previous = null) + public function __construct(string $message = '', $code = 300, Throwable $previous = null) { - parent::__construct($message, 3, $previous); + parent::__construct($message, $code, $previous); } } diff --git a/src/Exceptions/RelationWrongData.php b/src/Exceptions/RelationWrongData.php index ca7de04..0bd37a3 100644 --- a/src/Exceptions/RelationWrongData.php +++ b/src/Exceptions/RelationWrongData.php @@ -2,6 +2,12 @@ namespace iTRON\wpConnections\Exceptions; +use Throwable; + class RelationWrongData extends Exception { + public function __construct(string $message = '', $code = 400, Throwable $previous = null) + { + parent::__construct($message, $code, $previous); + } } diff --git a/src/Relation.php b/src/Relation.php index c039fac..0e2c59b 100644 --- a/src/Relation.php +++ b/src/Relation.php @@ -42,7 +42,7 @@ public function createConnection(Query\Connection $connectionQuery): Connection // Self-connection ability if (! $this->closurable && $connectionQuery->get('from') === $connectionQuery->get('to')) { - throw new Exceptions\ConnectionWrongData('Closurable not allowed by relation settings.'); + throw new Exceptions\ConnectionWrongData('Closurable not allowed by relation settings.', 301); } // Cardinality check @@ -56,7 +56,7 @@ public function createConnection(Query\Connection $connectionQuery): Connection $check_output = $this->findConnections($query); if (! $check_output->isEmpty()) { - throw new Exceptions\ConnectionWrongData('Cardinality violation.'); + throw new Exceptions\ConnectionWrongData('Cardinality violation.', 302); } } @@ -66,7 +66,7 @@ public function createConnection(Query\Connection $connectionQuery): Connection $check_input = $this->findConnections($query); if (! $check_input->isEmpty()) { - throw new Exceptions\ConnectionWrongData('Cardinality violation.'); + throw new Exceptions\ConnectionWrongData('Cardinality violation.', 302); } } @@ -77,7 +77,7 @@ public function createConnection(Query\Connection $connectionQuery): Connection if (! $this->duplicatable) { $check_duplicatable = $this->findConnections($query); if (!$check_duplicatable->isEmpty()) { - throw new Exceptions\ConnectionWrongData('Duplicatable violation.'); + throw new Exceptions\ConnectionWrongData('Duplicatable violation.', 303); } }