Skip to content

Commit

Permalink
Merge pull request #19 from hokoo/exception-codes
Browse files Browse the repository at this point in the history
Specific error codes got added
  • Loading branch information
hokoo authored Sep 10, 2024
2 parents 1cfbf38 + 1bd3efa commit 2965023
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Exceptions/ConnectionWrongData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
6 changes: 6 additions & 0 deletions src/Exceptions/RelationWrongData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
8 changes: 4 additions & 4 deletions src/Relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down

0 comments on commit 2965023

Please sign in to comment.