From 20f981b54cbbabc7144545f431815034ec6d80ec Mon Sep 17 00:00:00 2001 From: = Date: Wed, 21 Nov 2018 23:46:48 +0000 Subject: [PATCH] Better error-handling --- src/Command/SSL/CertImportCommand.php | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/Command/SSL/CertImportCommand.php b/src/Command/SSL/CertImportCommand.php index e7a6f7b..730a0e0 100644 --- a/src/Command/SSL/CertImportCommand.php +++ b/src/Command/SSL/CertImportCommand.php @@ -7,6 +7,8 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use GuzzleHttp\Exception\BadResponseException; + class CertImportCommand extends AbstractSSLCmd { protected $commandName = 'ssl:cert:import'; @@ -38,16 +40,17 @@ public function execute(InputInterface $input, OutputInterface $output) $cert = $input->getArgument('cert'); $privateKey = $input->getArgument('privateKey'); - $response = $this->api->import( - $this->token->token, - $input->getArgument('accountId'), - $this->getFile($input->getOption('csr')), - $this->getFile($input->getArgument('privateKey')), - $this->getFile($input->getArgument('cert')), - $this->getFile($input->getOption('chain')) - ); - - if ($response->getStatusCode() >= 400) { + try { + $response = $this->api->import( + $this->token->token, + $input->getArgument('accountId'), + $this->getFile($input->getOption('csr')), + $this->getFile($input->getArgument('privateKey')), + $this->getFile($input->getArgument('cert')), + $this->getFile($input->getOption('chain')) + ); + } catch (BadResponseException $e) { + $response = $e->getResponse(); $this->output->writeln("Could not import cert"); $this->output->writeln($response->getStatusCode()." - ".$response->getBody()->getContents()); exit(1);