Skip to content

Commit adbec40

Browse files
committed
fix(exceptions): add custom LogicException and improve method existence check
- Introduced `LogicException` extending `LaravelElasticsearchException`. - Created base `LaravelElasticsearchException` for custom exceptions. - Updated `MissingOrderException` to extend `LaravelElasticsearchException`. - Enhanced `Connection` to throw `LogicException` when method does not exist in `Bridge`. Why throw shade when you can throw exceptions? 🌩️
1 parent ef5e574 commit adbec40

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

src/Connection.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Illuminate\Support\Str;
1313
use PDPhilip\Elasticsearch\DSL\Bridge;
1414
use PDPhilip\Elasticsearch\DSL\Results;
15+
use PDPhilip\Elasticsearch\Exceptions\LogicException;
1516
use RuntimeException;
1617

1718
use function array_replace_recursive;
@@ -244,7 +245,13 @@ public function __call($method, $parameters)
244245
}
245246
$bridge = new Bridge($this);
246247

247-
return $bridge->{'process'.Str::studly($method)}(...$parameters);
248+
$methodName = 'process' . Str::studly($method);
249+
250+
if (! method_exists($bridge, $methodName)) {
251+
throw new LogicException("{$methodName} does not exist on the bridge.");
252+
}
253+
254+
return $bridge->{$methodName}(...$parameters);
248255
}
249256

250257
/** {@inheritdoc} */
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PDPhilip\Elasticsearch\Exceptions;
6+
7+
use Exception;
8+
9+
class LaravelElasticsearchException extends Exception {}

src/Exceptions/LogicException.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PDPhilip\Elasticsearch\Exceptions;
6+
7+
class LogicException extends LaravelElasticsearchException
8+
{
9+
10+
}

src/Exceptions/MissingOrderException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use Exception;
88

9-
class MissingOrderException extends Exception
9+
class MissingOrderException extends LaravelElasticsearchException
1010
{
1111
// private array $_details;
1212

0 commit comments

Comments
 (0)