Skip to content

Commit 376f040

Browse files
committed
IMP: Add custom exception for HTTPClient type
1 parent 10d7ff0 commit 376f040

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Mooore\WordpressIntegrationCms\Exception;
7+
8+
/**
9+
* Magento mail exception
10+
*
11+
* @api
12+
* @since 100.0.2
13+
*/
14+
class HTTPClientTypeRequiredException extends \Exception
15+
{
16+
}

Model/HttpClient/Wordpress.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Psr\Log\LoggerInterface;
88
use Symfony\Component\HttpClient\HttpClient;
99
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
10+
use Mooore\WordpressIntegrationCms\Exception\HTTPClientTypeRequiredException;
1011

1112
abstract class Wordpress
1213
{
@@ -49,11 +50,12 @@ public function setBaseUrl(string $baseUrl)
4950
* @throws \Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface
5051
* @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface
5152
* @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
53+
* @throws HTTPClientTypeRequiredException
5254
*/
5355
public function all(int $pageSize = 10, array $filters = []): \Generator
5456
{
5557
if (is_null($this->type)) {
56-
throw new \Exception("Type is required for HTTPClient");
58+
throw new HTTPClientTypeRequiredException("Type is required for HTTPClient");
5759
}
5860
$peekHeaders = $this->peek($pageSize);
5961

@@ -95,22 +97,26 @@ public function all(int $pageSize = 10, array $filters = []): \Generator
9597
* @throws \Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface
9698
* @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface
9799
* @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
100+
* @throws HTTPClientTypeRequiredException
98101
*/
99102
public function get(int $id): array
100103
{
101104
if (is_null($this->type)) {
102-
throw new \Exception("Type is required for HTTPClient");
105+
throw new HTTPClientTypeRequiredException("Type is required for HTTPClient");
103106
}
104107

105108
$response = $this->client->request('GET', static::WP_JSON_URL_PREFIX . $this->type . '/' . $id);
106109

107110
return json_decode($response->getContent(), true);
108111
}
109112

113+
/**
114+
* @throws HTTPClientTypeRequiredException
115+
*/
110116
public function postMetaDataToPage(int $pageId, string $key, string $value, string $authentication)
111117
{
112118
if (is_null($this->type)) {
113-
throw new \Exception("Type is required for HTTPClient");
119+
throw new HTTPClientTypeRequiredException("Type is required for HTTPClient");
114120
}
115121

116122
try {
@@ -136,11 +142,12 @@ public function postMetaDataToPage(int $pageId, string $key, string $value, stri
136142
* @throws \Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface
137143
* @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface
138144
* @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
145+
* @throws HTTPClientTypeRequiredException
139146
*/
140147
public function peek(int $pageSize): array
141148
{
142149
if (is_null($this->type)) {
143-
throw new \Exception("Type is required for HTTPClient");
150+
throw new HTTPClientTypeRequiredException("Type is required for HTTPClient");
144151
}
145152

146153
$peekResponse = $this->client->request('HEAD', static::WP_JSON_URL_PREFIX . $this->type . '?per_page=' . $pageSize);

0 commit comments

Comments
 (0)