Skip to content

Commit 780d007

Browse files
authored
[DEVX-1656] Handle eVCS/STA exceptions from backend. (#2505)
* Back to dev 3.2.3. * Handle ICR exceptions from ygg. * Use 409 instead of 410. * Rename and introduce sta exception. * Handle workflow creation errors and use constants. * Do not catch exceptions, let it fail. * Remove unused imports. * Also add sta handling for request. * Fix linting. * Update to match API. * Fix typos.
1 parent 2896200 commit 780d007

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

src/Collections/Workflows.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Pantheon\Terminus\Collections;
44

55
use Pantheon\Terminus\Exceptions\TerminusException;
6+
use Pantheon\Terminus\Exceptions\TerminusUnsupportedSiteException;
67
use Pantheon\Terminus\Models\Environment;
78
use Pantheon\Terminus\Models\Organization;
89
use Pantheon\Terminus\Models\Site;
@@ -11,6 +12,7 @@
1112
use Pantheon\Terminus\Models\Workflow;
1213
use Pantheon\Terminus\Session\SessionAwareInterface;
1314
use Pantheon\Terminus\Session\SessionAwareTrait;
15+
use Pantheon\Terminus\Request\Request;
1416

1517
/**
1618
* Class Workflows
@@ -104,6 +106,18 @@ public function create($type, array $options = []): Workflow
104106
]
105107
);
106108
if ($results->isError()) {
109+
if ($results->getStatusCode() == 409) {
110+
$decoded_body = json_decode($results->getData(), false);
111+
if (!empty($decoded_body) && !empty($decoded_body->message)) {
112+
// This request is expected to fail for an unsupported site, throw exception.
113+
throw new TerminusUnsupportedSiteException($decoded_body->message);
114+
} elseif (!empty($decoded_body) && !empty($decoded_body->reason)) {
115+
// This request is expected to fail, use generic reason.
116+
throw new TerminusUnsupportedSiteException(
117+
Request::UNSUPPORTED_SITE_EXCEPTION_MESSAGE
118+
);
119+
}
120+
}
107121
throw new TerminusException(
108122
"Workflow Creation Failed: {error}",
109123
['error' => $results->getStatusCodeReason()]
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 TerminusUnsupportedSiteException
7+
* @package Pantheon\Terminus\Exceptions
8+
*/
9+
class TerminusUnsupportedSiteException extends TerminusException
10+
{
11+
}

src/Request/Request.php

Lines changed: 16 additions & 1 deletion
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\TerminusUnsupportedSiteException;
1819
use Pantheon\Terminus\Helpers\LocalMachineHelper;
1920
use Pantheon\Terminus\Helpers\Utility\TraceId;
2021
use Pantheon\Terminus\Session\SessionAwareInterface;
@@ -73,6 +74,8 @@ class Request implements
7374
'CI',
7475
];
7576

77+
public const UNSUPPORTED_SITE_EXCEPTION_MESSAGE = 'This is not supported for this site.';
78+
7679
protected ClientInterface $client;
7780

7881
/**
@@ -229,7 +232,7 @@ private function createRetryDecider(): callable
229232
);
230233
} else {
231234
if (preg_match('/[2,4]0\d/', $response->getStatusCode())) {
232-
// Do not retry on 20x and 40x responses.
235+
// Do not retry on 20x or 40x responses.
233236
return false;
234237
}
235238

@@ -441,6 +444,18 @@ public function request($path, array $options = []): RequestOperationResult
441444
}
442445
}
443446

447+
if ($response->getStatusCode() == 409) {
448+
if (!empty($decoded_body) && !empty($decoded_body->message)) {
449+
// This request is expected to fail for an unsupported site, throw exception.
450+
throw new TerminusUnsupportedSiteException($decoded_body->message);
451+
} elseif (!empty($decoded_body) && !empty($decoded_body->reason)) {
452+
// This request is expected to fail, use generic reason.
453+
throw new TerminusUnsupportedSiteException(
454+
self::UNSUPPORTED_SITE_EXCEPTION_MESSAGE
455+
);
456+
}
457+
}
458+
444459
return new RequestOperationResult([
445460
'data' => $decoded_body ?? $body,
446461
'headers' => $headers,

0 commit comments

Comments
 (0)