- 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;
class MandatoryFieldException extends \InvalidArgumentException {}
class MandatoryFieldException extends LeanApiException {}

View File

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

View File

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

View File

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