|
5 | 5 | use UnitPhpSdk\Contracts\{CertificateInterface, UnitInterface, Uploadable}; |
6 | 6 | use Override; |
7 | 7 | use UnitPhpSdk\Abstract\AbstractApplication; |
| 8 | +use UnitPhpSdk\Config\Listener; |
| 9 | +use UnitPhpSdk\Config\Route; |
| 10 | +use UnitPhpSdk\Config\Upstream; |
8 | 11 | use UnitPhpSdk\Enums\ApiPathEnum; |
9 | 12 | use UnitPhpSdk\Enums\HttpMethodsEnum; |
10 | 13 | use UnitPhpSdk\Exceptions\FileNotFoundException; |
@@ -60,7 +63,8 @@ class Unit implements UnitInterface |
60 | 63 | public function __construct( |
61 | 64 | private readonly string $address, |
62 | 65 | private readonly ?string $socket = null, |
63 | | - ) { |
| 66 | + ) |
| 67 | + { |
64 | 68 | $this->request = new UnitRequest( |
65 | 69 | address: $this->address, |
66 | 70 | socket: $this->socket |
@@ -145,11 +149,15 @@ public function removeCertificate(string $certificateName): bool |
145 | 149 | $this->request |
146 | 150 | ->setMethod(HttpMethodsEnum::DELETE) |
147 | 151 | ->send(ApiPathEnum::CERTIFICATE->getPath($certificateName)); |
148 | | - } catch (UnitException) { |
149 | | - return false; |
150 | | - } |
151 | 152 |
|
152 | | - return true; |
| 153 | + return true; |
| 154 | + } catch (UnitException $exception) { |
| 155 | + if ($exception->getCode() == 404) { |
| 156 | + throw new UnitException('Certificate not found'); |
| 157 | + } |
| 158 | + |
| 159 | + throw new UnitException($exception->getMessage()); |
| 160 | + } |
153 | 161 | } |
154 | 162 |
|
155 | 163 | /** |
@@ -325,9 +333,9 @@ public function restartApplication(AbstractApplication $application): bool |
325 | 333 | #[Override] public function toArray(): array |
326 | 334 | { |
327 | 335 | return [ |
328 | | - 'certificates' => array_map(fn ($certificate) => $certificate->toArray(), $this->getCertificates()), |
| 336 | + 'certificates' => array_map(fn($certificate) => $certificate->toArray(), $this->getCertificates()), |
329 | 337 | 'config' => $this->getConfig()->toArray(), |
330 | | - 'js_modules' => array_map(fn ($module) => $module->toArray(), $this->getJsModules()), |
| 338 | + 'js_modules' => array_map(fn($module) => $module->toArray(), $this->getJsModules()), |
331 | 339 | 'status' => $this->getStatistics()->toArray() |
332 | 340 | ]; |
333 | 341 | } |
|
0 commit comments