Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/Exception/Api/NotFoundException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace RetailCrm\Api\Exception\Api;

use RetailCrm\Api\Exception\ApiException;
use RetailCrm\Api\Model\Entity\Customers\Customer;

/**
* Class NotFoundException
*
* @category NotFoundException
* @package RetailCrm\Api\Exception\Api
*/
class NotFoundException extends ApiException
{
public function getCombinedTo(): ?Customer
{
return $this->getErrorResponse()->combinedTo;
}
}
2 changes: 2 additions & 0 deletions src/Factory/ApiExceptionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
];

/**
Expand Down
8 changes: 8 additions & 0 deletions src/Model/Response/ErrorResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
22 changes: 22 additions & 0 deletions tests/src/Factory/ApiExceptionFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}