From 51d55760fa037245681d89efd135a2ac924d0f46 Mon Sep 17 00:00:00 2001 From: szaimen Date: Sat, 1 Jan 2022 16:01:31 +0100 Subject: [PATCH] don't crash during container removal if the container doesn't exist Signed-off-by: szaimen --- php/src/Docker/DockerActionManager.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/php/src/Docker/DockerActionManager.php b/php/src/Docker/DockerActionManager.php index 9a424108..34c7e669 100644 --- a/php/src/Docker/DockerActionManager.php +++ b/php/src/Docker/DockerActionManager.php @@ -125,7 +125,11 @@ class DockerActionManager $url = $this->BuildApiUrl(sprintf('containers/%s', urlencode($container->GetIdentifier()))); try { $this->guzzleClient->delete($url); - } catch (\Exception $e) {} + } catch (ClientException $e) { + if ($e->getCode() !== 404) { + throw $e; + } + } } public function GetLogs(Container $container) : string @@ -426,7 +430,7 @@ class DockerActionManager ], ] ); - } catch (ServerException $e) {} + } catch (ClientException $e) {} } private function ConnectContainerIdToNetwork(string $id) @@ -482,7 +486,9 @@ class DockerActionManager public function StopContainer(Container $container) { $url = $this->BuildApiUrl(sprintf('containers/%s/stop?t=%s', urlencode($container->GetIdentifier()), $container->GetMaxShutdownTime())); - $this->guzzleClient->post($url); + try { + $this->guzzleClient->post($url); + } catch (\Exception $e) {} } public function GetBackupcontainerExitCode() : int