<?php
namespace Fifa\ConnectServiceBus\Sdk\ExceptionHandler\Handler;

use Fifa\ConnectServiceBus\Sdk\Api\ApiException;
use Fifa\ConnectServiceBus\Sdk\Exception\FifaConnectServiceBusSdkException;
use Fifa\ConnectServiceBus\Sdk\Exception\QueueExistsException;
use Fifa\ConnectServiceBus\Sdk\FifaConnectServiceBusClientInterface;

/**
 * Class QueueAlreadyExistsHandler
 * @package Fifa\ConnectServiceBus\Sdk\ExceptionHandler\Handler
 */
class QueueAlreadyExistsHandler implements HandlerInterface
{
    /**
     * Method handles an QueueExistsException
     *
     * @param ApiException $e
     * @return FifaConnectServiceBusSdkException|null
     */
    public function handle(ApiException $e)
    {
        if ($e->getCode() == FifaConnectServiceBusClientInterface::HTTP_CODE_CONFLICT)
        {
            return new QueueExistsException($e, 'Queue already exists');
        }

        return null;
    }
}