- WIP on exceptions handling and throwing
This commit is contained in:
parent
382a4459d7
commit
0443f5a811
5
src/Exception/LeanApiException.php
Normal file
5
src/Exception/LeanApiException.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Lean\Api\Exception;
|
||||
|
||||
class LeanApiException extends \InvalidArgumentException {}
|
||||
@ -2,4 +2,4 @@
|
||||
|
||||
namespace Lean\Api\Exception;
|
||||
|
||||
class MandatoryFieldException extends \InvalidArgumentException {}
|
||||
class MandatoryFieldException extends LeanApiException {}
|
||||
@ -2,4 +2,4 @@
|
||||
|
||||
namespace Lean\Api\Exception;
|
||||
|
||||
class MaximumLengthException extends \InvalidArgumentException {}
|
||||
class MaximumLengthException extends LeanApiException {}
|
||||
@ -2,4 +2,4 @@
|
||||
|
||||
namespace Lean\Api\Exception;
|
||||
|
||||
class MinimumLengthException extends \InvalidArgumentException {}
|
||||
class MinimumLengthException extends LeanApiException {}
|
||||
@ -2,4 +2,4 @@
|
||||
|
||||
namespace Lean\Api\Exception;
|
||||
|
||||
class RegexFormatException extends \InvalidArgumentException {}
|
||||
class RegexFormatException extends LeanApiException{}
|
||||
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user