- WIP on exceptions handling and throwing

This commit is contained in:
Dave M. 2026-07-06 13:41:35 +00:00
parent 382a4459d7
commit 0443f5a811
6 changed files with 13 additions and 7 deletions

View File

@ -0,0 +1,5 @@
<?php
namespace Lean\Api\Exception;
class LeanApiException extends \InvalidArgumentException {}

View File

@ -2,4 +2,4 @@
namespace Lean\Api\Exception; namespace Lean\Api\Exception;
class MandatoryFieldException extends \InvalidArgumentException {} class MandatoryFieldException extends LeanApiException {}

View File

@ -2,4 +2,4 @@
namespace Lean\Api\Exception; namespace Lean\Api\Exception;
class MaximumLengthException extends \InvalidArgumentException {} class MaximumLengthException extends LeanApiException {}

View File

@ -2,4 +2,4 @@
namespace Lean\Api\Exception; namespace Lean\Api\Exception;
class MinimumLengthException extends \InvalidArgumentException {} class MinimumLengthException extends LeanApiException {}

View File

@ -2,4 +2,4 @@
namespace Lean\Api\Exception; namespace Lean\Api\Exception;
class RegexFormatException extends \InvalidArgumentException {} class RegexFormatException extends LeanApiException{}

View File

@ -6,7 +6,9 @@ use CSLSJ\Lean\Form\Session\EmailContext;
use Picea\Ui\Method\{FormContext, FormContextInterface}; use Picea\Ui\Method\{FormContext, FormContextInterface};
use Lean\Api\Attribute\ContextField; use Lean\Api\Attribute\ContextField;
use Lean\Api\Exception\LeanApiException;
use Lean\Api\Exception\MandatoryFieldException; use Lean\Api\Exception\MandatoryFieldException;
use Lean\Api\Exception\MinimumLengthException;
use Notes\Common\ReflectedProperty; use Notes\Common\ReflectedProperty;
use Notes\ObjectReflection; use Notes\ObjectReflection;
use Ulmus\Attribute\Property\Field; use Ulmus\Attribute\Property\Field;
@ -107,9 +109,8 @@ abstract class Save extends Form implements \Picea\Ui\Method\FormInterface {
if ($attribute) { if ($attribute) {
try { try {
$attribute->object->assertValueSpecs($context->$name ?? null, ! $this->getEntity()->isLoaded()); $attribute->object->assertValueSpecs($context->$name ?? null, ! $this->getEntity()->isLoaded());
} } catch (LeanApiException $e) {
catch(\Throwable $ex) { throw new MandatoryFieldException("An error occured with field '$name': " . $e->getMessage());
throw new MandatoryFieldException("An error occured with field '$name': " . $ex->getMessage());
} }
} }
} }