Skip to content

Commit b666f4e

Browse files
committed
Handle ICR exceptions from ygg.
1 parent 2098160 commit b666f4e

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

src/Commands/Branch/ListCommand.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Pantheon\Terminus\Commands\StructuredListTrait;
88
use Pantheon\Terminus\Site\SiteAwareInterface;
99
use Pantheon\Terminus\Site\SiteAwareTrait;
10+
use Pantheon\Terminus\Exceptions\TerminusIcrSiteException;
1011

1112
/**
1213
* Class ListCommand
@@ -37,6 +38,12 @@ class ListCommand extends TerminusCommand implements SiteAwareInterface
3738
*/
3839
public function listBranches($site_id)
3940
{
40-
return $this->getRowsOfFields($this->getSiteById($site_id)->getBranches());
41+
try {
42+
return $this->getRowsOfFields($this->getSiteById($site_id)->getBranches());
43+
} catch (TerminusIcrSiteException $e) {
44+
$this->log()->notice("This is an ICR site, branches are managed in the external VCS.");
45+
$this->log()->debug($e->getMessage());
46+
return;
47+
}
4148
}
4249
}

src/Commands/Connection/SetCommand.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Pantheon\Terminus\Site\SiteAwareInterface;
88
use Pantheon\Terminus\Site\SiteAwareTrait;
99
use Pantheon\Terminus\Exceptions\TerminusException;
10+
use Pantheon\Terminus\Exceptions\TerminusIcrSiteException;
1011

1112
/**
1213
* Class SetCommand.
@@ -64,6 +65,10 @@ public function connectionSet($site_env, $mode)
6465
try {
6566
$mode = strtolower($mode ?? '');
6667
$workflow = $env->changeConnectionMode($mode);
68+
} catch (TerminusIcrSiteException $e) {
69+
$this->log()->debug($e->getMessage());
70+
$this->log()->notice("This is an ICR site, connection mode switching is not currently supported.");
71+
return;
6772
} catch (TerminusException $e) {
6873
$message = $e->getMessage();
6974
if (strpos($message, $mode) !== false) {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Pantheon\Terminus\Exceptions;
4+
5+
/**
6+
* Class TerminusIcrSiteException
7+
* @package Pantheon\Terminus\Exceptions
8+
*/
9+
class TerminusIcrSiteException extends TerminusException
10+
{
11+
}

src/Request/Request.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use League\Container\ContainerAwareTrait;
1616
use Pantheon\Terminus\Config\ConfigAwareTrait;
1717
use Pantheon\Terminus\Exceptions\TerminusException;
18+
use Pantheon\Terminus\Exceptions\TerminusIcrSiteException;
1819
use Pantheon\Terminus\Helpers\LocalMachineHelper;
1920
use Pantheon\Terminus\Session\SessionAwareInterface;
2021
use Pantheon\Terminus\Session\SessionAwareTrait;
@@ -226,8 +227,8 @@ private function createRetryDecider(): callable
226227
['error' => $exception->getMessage()]
227228
);
228229
} else {
229-
if (preg_match('/[2,4]0\d/', $response->getStatusCode())) {
230-
// Do not retry on 20x and 40x responses.
230+
if (preg_match('/[2,4]0\d/', $response->getStatusCode()) || $response->getStatusCode() == 410) {
231+
// Do not retry on 20x, 40x or 410 responses.
231232
return false;
232233
}
233234

@@ -427,6 +428,11 @@ public function request($path, array $options = []): RequestOperationResult
427428
$this->logger->debug($jsonException->getMessage());
428429
}
429430

431+
if ($response->getStatusCode() == 410 && $body == "icr_site") {
432+
// This request is expected to fail for an ICR site, throw exception that will be catched down the road.
433+
throw new TerminusIcrSiteException("This is an ICR site.");
434+
}
435+
430436
return new RequestOperationResult([
431437
'data' => $body,
432438
'headers' => $response->getHeaders(),

0 commit comments

Comments
 (0)