Skip to content

Commit c63fdf2

Browse files
committed
Update TPPWholesaleResponse to gracefully handle HTML responses
1 parent 701aa48 commit c63fdf2

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/TPPWholesale/Helper/TPPWholesaleResponse.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Upmind\ProvisionProviders\DomainNames\TPPWholesale\Helper;
66

7+
use Illuminate\Support\Str;
78
use Upmind\ProvisionBase\Exception\ProvisionFunctionError;
89

910
class TPPWholesaleResponse implements \JsonSerializable
@@ -107,7 +108,7 @@ private function throwError(string $message, int $errorCode): void
107108
{
108109
throw ProvisionFunctionError::create(sprintf('Provider API Error: %d: %s ', $errorCode, $message))
109110
->withData([
110-
'response' => $this->response,
111+
'response' => Str::limit($this->response, 500),
111112
]);
112113
}
113114

@@ -121,6 +122,10 @@ private function throwResponseError(?string $response = null): void
121122
{
122123
$errorDescription = 'Unknown error';
123124

125+
if (!Str::contains($this->response, "ERR:")) {
126+
$this->throwError('Unknown error', 0);
127+
}
128+
124129
list(, $errorData) = explode("ERR: ", $response ?? $this->response, 2);
125130
if (str_contains($errorData, ',')) {
126131
list($errorCode, $errorDescription) = explode(",", $errorData, 2);
@@ -140,7 +145,7 @@ private function throwResponseError(?string $response = null): void
140145
public function parseAuthResponse(): string
141146
{
142147
$sessionId = "";
143-
if (str_starts_with($this->response, "ERR:")) {
148+
if (str_starts_with($this->response, "ERR:") || !Str::contains($this->response, "OK:")) {
144149
$this->throwResponseError();
145150
} else {
146151
list(, $sessionId) = explode("OK: ", $this->response, 2);

0 commit comments

Comments
 (0)