Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit f0c1b48

Browse files
authored
Merge pull request #14 from rossbearman/fix-exception
Throw ActiveCampaignException instead of RequestException on HTTP error
2 parents 1d581f9 + 8011219 commit f0c1b48

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/Exceptions/ActiveCampaignException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace Label84\ActiveCampaign\Exceptions;
44

5-
use Exception;
5+
use Illuminate\Http\Client\RequestException;
66

7-
class ActiveCampaignException extends Exception
7+
class ActiveCampaignException extends RequestException
88
{
99
//
1010
}

src/Resources/ActiveCampaignBaseResource.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Label84\ActiveCampaign\Resources;
44

55
use Illuminate\Http\Client\PendingRequest;
6+
use Illuminate\Http\Client\RequestException;
67
use Illuminate\Http\Client\Response;
78
use Label84\ActiveCampaign\ActiveCampaignService;
89
use Label84\ActiveCampaign\Exceptions\ActiveCampaignException;
@@ -17,15 +18,18 @@ public function __construct(
1718
$this->client = $this->service->makeRequest();
1819
}
1920

21+
/**
22+
* @throws ActiveCampaignException
23+
*/
2024
public function request(string $method, string $path, array $data = [], ?string $responseKey = null): array
2125
{
22-
/** @var Response $response */
23-
$response = $this->client->$method($path, $data);
26+
try {
27+
/** @var Response $response */
28+
$response = $this->client->$method($path, $data);
2429

25-
if ($response->failed()) {
26-
throw new ActiveCampaignException($response->json());
30+
return $response->throw()->json($responseKey);
31+
} catch (RequestException $exception) {
32+
throw new ActiveCampaignException($exception->response);
2733
}
28-
29-
return $response->throw()->json($responseKey);
3034
}
3135
}

0 commit comments

Comments
 (0)