Skip to content

Commit f95ba1b

Browse files
committed
Update to match API.
1 parent 59050e8 commit f95ba1b

File tree

5 files changed

+35
-48
lines changed

5 files changed

+35
-48
lines changed

src/Collections/Workflows.php

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

55
use Pantheon\Terminus\Exceptions\TerminusException;
6-
use Pantheon\Terminus\Exceptions\TerminusEvcsSiteException;
7-
use Pantheon\Terminus\Exceptions\TerminusStaSiteException;
6+
use Pantheon\Terminus\Exceptions\TerminusUnsupportedSiteException;
87
use Pantheon\Terminus\Models\Environment;
98
use Pantheon\Terminus\Models\Organization;
109
use Pantheon\Terminus\Models\Site;
@@ -107,13 +106,17 @@ public function create($type, array $options = []): Workflow
107106
]
108107
);
109108
if ($results->isError()) {
110-
if ($results->getStatusCode() === 409 && $results->getData() === Request::EVCS_SITE_RESPONSE) {
111-
// EVCS site unsupported workflow, throw specific exception.
112-
throw new TerminusEvcsSiteException(Request::EVCS_SITE_EXCEPTION_MESSAGE);
113-
}
114-
if ($results->getStatusCode() === 409 && $results->getData() === Request::STA_SITE_RESPONSE) {
115-
// STA site unsupported workflow, throw specific exception.
116-
throw new TerminusStaSiteException(Request::STA_SITE_EXCEPTION_MESSAGE);
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 reson.
116+
throw new TerminusUnsupportedSiteException(
117+
Request::UNSUPPORTED_SITE_EXCEPTION_MESSAGE
118+
);
119+
}
117120
}
118121
throw new TerminusException(
119122
"Workflow Creation Failed: {error}",

src/Exceptions/TerminusEvcsSiteException.php

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/Exceptions/TerminusStaSiteException.php

Lines changed: 0 additions & 11 deletions
This file was deleted.
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: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use League\Container\ContainerAwareTrait;
1616
use Pantheon\Terminus\Config\ConfigAwareTrait;
1717
use Pantheon\Terminus\Exceptions\TerminusException;
18-
use Pantheon\Terminus\Exceptions\TerminusEvcsSiteException;
18+
use Pantheon\Terminus\Exceptions\TerminusUnsupportedSiteException;
1919
use Pantheon\Terminus\Helpers\LocalMachineHelper;
2020
use Pantheon\Terminus\Helpers\Utility\TraceId;
2121
use Pantheon\Terminus\Session\SessionAwareInterface;
@@ -74,14 +74,7 @@ class Request implements
7474
'CI',
7575
];
7676

77-
public const EVCS_SITE_RESPONSE = 'evcs_site';
78-
79-
public const EVCS_SITE_EXCEPTION_MESSAGE =
80-
'This is a site with an external version control system so this is not supported.';
81-
82-
public const STA_SITE_RESPONSE = 'sta_site';
83-
84-
public const STA_SITE_EXCEPTION_MESSAGE = 'This is not supported for this site.';
77+
public const UNSUPPORTED_SITE_EXCEPTION_MESSAGE = 'This is not supported for this site.';
8578

8679
protected ClientInterface $client;
8780

@@ -451,14 +444,16 @@ public function request($path, array $options = []): RequestOperationResult
451444
}
452445
}
453446

454-
if ($response->getStatusCode() == 409 && $body == self::EVCS_SITE_RESPONSE) {
455-
// This request is expected to fail for an eVCS site, throw exception.
456-
throw new TerminusEvcsSiteException(self::EVCS_SITE_EXCEPTION_MESSAGE);
457-
}
458-
459-
if ($response->getStatusCode() == 409 && $body == self::STA_SITE_RESPONSE) {
460-
// This request is expected to fail for an STA site, throw exception.
461-
throw new TerminusEvcsSiteException(self::STA_SITE_EXCEPTION_MESSAGE);
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 reson.
453+
throw new TerminusUnsupportedSiteException(
454+
self::UNSUPPORTED_SITE_EXCEPTION_MESSAGE
455+
);
456+
}
462457
}
463458

464459
return new RequestOperationResult([

0 commit comments

Comments
 (0)