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

use Fifa\ConnectId\Sdk\Api\ApiException;
use Fifa\ConnectId\Sdk\Exception\FifaEntityNotFoundException;

/**
 * Class FifaEntityNotFoundHandler
 * @package Fifa\ConnectId\Sdk\ExceptionHandler\Handler
 */
class FifaEntityNotFoundHandler implements HandlerInterface
{
    /**
     * Handler method for FifaEntityNotFoundException
     *
     * @param ApiException $e
     * @return FifaEntityNotFoundException|null
     */
    public function handle(ApiException $e): ?FifaEntityNotFoundException
    {
        if ($e->getCode() == 404) {
            return new FifaEntityNotFoundException($e, is_string($e->getResponseBody()) ? $e->getResponseBody() : $e->getMessage());
        }

        return null;
    }
}