refs #2137. Removed subred fixed
testing/ogcore-api/pipeline/head There was a failure building this commit Details

develop
Manuel Aranda Rosales 2025-05-30 08:37:36 +02:00
parent 6abf065dec
commit b86e51e1bb
1 changed files with 14 additions and 1 deletions

View File

@ -7,6 +7,7 @@ use App\Entity\Subnet;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
@ -29,11 +30,23 @@ class DeleteAction extends AbstractOgDhcpController
throw new ValidatorException('Data Id is required');
}
$content = $this->createRequest('DELETE', 'http://'.$this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$data->getServerId());
try {
$content = $this->createRequest(
'DELETE',
'http://' . $this->ogDhcpApiUrl . '/ogdhcp/v1/subnets/' . $data->getServerId()
);
} catch (HttpException $e) {
if ($e->getStatusCode() === 404) {
$content = ['message' => 'Subnet not found on external API, proceeding with local deletion'];
} else {
throw $e;
}
}
$this->entityManager->remove($data);
$this->entityManager->flush();
return new JsonResponse(data: $content, status: Response::HTTP_OK);
}
}