- 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;
|
namespace Lean\Api\Exception;
|
||||||
|
|
||||||
class MandatoryFieldException extends \InvalidArgumentException {}
|
class MandatoryFieldException extends LeanApiException {}
|
||||||
@ -2,4 +2,4 @@
|
|||||||
|
|
||||||
namespace Lean\Api\Exception;
|
namespace Lean\Api\Exception;
|
||||||
|
|
||||||
class MaximumLengthException extends \InvalidArgumentException {}
|
class MaximumLengthException extends LeanApiException {}
|
||||||
@ -2,4 +2,4 @@
|
|||||||
|
|
||||||
namespace Lean\Api\Exception;
|
namespace Lean\Api\Exception;
|
||||||
|
|
||||||
class MinimumLengthException extends \InvalidArgumentException {}
|
class MinimumLengthException extends LeanApiException {}
|
||||||
@ -2,4 +2,4 @@
|
|||||||
|
|
||||||
namespace Lean\Api\Exception;
|
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 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());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user