diff --git a/src/Exception/Api/NotFoundException.php b/src/Exception/Api/NotFoundException.php new file mode 100644 index 000000000..7ad5e8d0d --- /dev/null +++ b/src/Exception/Api/NotFoundException.php @@ -0,0 +1,20 @@ +getErrorResponse()->combinedTo; + } +} diff --git a/src/Factory/ApiExceptionFactory.php b/src/Factory/ApiExceptionFactory.php index 56b056233..a8b484e55 100644 --- a/src/Factory/ApiExceptionFactory.php +++ b/src/Factory/ApiExceptionFactory.php @@ -15,6 +15,7 @@ use RetailCrm\Api\Exception\Api\InvalidCredentialsException; use RetailCrm\Api\Exception\Api\MissingCredentialsException; use RetailCrm\Api\Exception\Api\MissingParameterException; +use RetailCrm\Api\Exception\Api\NotFoundException; use RetailCrm\Api\Exception\Api\ValidationException; use RetailCrm\Api\Exception\ApiException; use RetailCrm\Api\Interfaces\ResponseInterface; @@ -37,6 +38,7 @@ class ApiExceptionFactory 'Account does not exist.' => AccountDoesNotExistException::class, 'Errors in the entity format' => ValidationException::class, 'Validation error' => ValidationException::class, + 'Not found' => NotFoundException::class, ]; /** diff --git a/src/Model/Response/ErrorResponse.php b/src/Model/Response/ErrorResponse.php index bc0a18f5c..9bfd9c2a2 100644 --- a/src/Model/Response/ErrorResponse.php +++ b/src/Model/Response/ErrorResponse.php @@ -42,4 +42,12 @@ public function __construct() * @JMS\SerializedName("errorMsg") */ public $errorMsg; + + /** + * @var \RetailCrm\Api\Model\Entity\Customers\Customer + * + * @JMS\Type("RetailCrm\Api\Model\Entity\Customers\Customer") + * @JMS\SerializedName("combinedTo") + */ + public $combinedTo; } diff --git a/tests/src/Factory/ApiExceptionFactoryTest.php b/tests/src/Factory/ApiExceptionFactoryTest.php index e0481d8db..de55477b7 100644 --- a/tests/src/Factory/ApiExceptionFactoryTest.php +++ b/tests/src/Factory/ApiExceptionFactoryTest.php @@ -13,8 +13,10 @@ use RetailCrm\Api\Exception\Api\ApiErrorException; use RetailCrm\Api\Exception\Api\MissingCredentialsException; use RetailCrm\Api\Exception\Api\MissingParameterException; +use RetailCrm\Api\Exception\Api\NotFoundException; use RetailCrm\Api\Exception\Api\ValidationException; use RetailCrm\Api\Factory\ApiExceptionFactory; +use RetailCrm\Api\Model\Entity\Customers\Customer; use RetailCrm\Api\Model\Response\ErrorResponse; use RetailCrm\Api\Model\Response\SuccessResponse; use RetailCrm\TestUtils\TestCase\AbstractApiResourceGroupTestCase; @@ -126,4 +128,24 @@ public function testValidationError(): void self::assertFalse($exception->getErrorResponse()->success); self::assertStringContainsString($exception->getMessage(), (string) $exception); } + + public function testNotFoundError(): void + { + $response = new ErrorResponse(); + $response->errorMsg = "Not found"; + $response->errors = []; + $response->combinedTo = new Customer(); + $response->combinedTo->id = 1; + + $exception = $this->factory->createException($response, 400); + + self::assertInstanceOf(NotFoundException::class, $exception); + self::assertEquals(400, $exception->getCode()); + self::assertEquals(400, $exception->getStatusCode()); + self::assertEquals($response->errorMsg, $exception->getErrorResponse()->errorMsg); + self::assertFalse($exception->getErrorResponse()->success); + self::assertStringContainsString($exception->getMessage(), (string) $exception); + self::assertInstanceOf(Customer::class, $exception->getCombinedTo()); + self::assertEquals(1, $exception->getCombinedTo()->id); + } }