From 82ca32171570692f115bbc797bf6d58f0aa72b2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 11 Dec 2023 22:47:15 +0100 Subject: [PATCH] Add exceptions for async file handling failures Introduced two new exceptions, `BadCallToRemoteServer` and `TempUrlRemoteServerException`, to improve error handling in asynchronous file operations. These exceptions are thrown when there are issues with the remote server during an async file operation such as HTTP status codes >= 400 and if the server is unreachable. --- .../Exception/BadCallToRemoteServer.php | 20 +++++++++++++++++++ .../TempUrlRemoteServerException.php | 20 +++++++++++++++++++ .../Constraints/AsyncFileExistsValidator.php | 11 +++++++++- 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 src/Bundle/ChillDocStoreBundle/AsyncUpload/Exception/BadCallToRemoteServer.php create mode 100644 src/Bundle/ChillDocStoreBundle/AsyncUpload/Exception/TempUrlRemoteServerException.php diff --git a/src/Bundle/ChillDocStoreBundle/AsyncUpload/Exception/BadCallToRemoteServer.php b/src/Bundle/ChillDocStoreBundle/AsyncUpload/Exception/BadCallToRemoteServer.php new file mode 100644 index 000000000..58ddfe0b0 --- /dev/null +++ b/src/Bundle/ChillDocStoreBundle/AsyncUpload/Exception/BadCallToRemoteServer.php @@ -0,0 +1,20 @@ +client->request('HEAD', $urlHead->url); - if (404 === $response->getStatusCode()) { + if (404 === $status = $response->getStatusCode()) { $this->context->buildViolation($constraint->message) ->setParameter('{{ filename }}', $file) ->addViolation(); + } elseif (500 <= $status) { + throw new TempUrlRemoteServerException($response->getStatusCode()); + } elseif (400 <= $status) { + throw new BadCallToRemoteServer($response->getContent(false), $response->getStatusCode()); } } catch (HttpExceptionInterface $exception) { if (404 !== $exception->getResponse()->getStatusCode()) { throw $exception; } + } catch (TransportExceptionInterface $e) { + throw new TempUrlRemoteServerException(0, previous: $e); } } }