Skip to content

Commit a73c02f

Browse files
committed
fix: 🐛 get http response code
1 parent 7011ab0 commit a73c02f

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/Support/Http.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ public static function withHeaders(array $headers): static
3939
*
4040
* @param string $url
4141
* @param array $headers
42-
* @return object|null
42+
* @return HttpResponseInterface
43+
*
44+
* @throws HttpException
4345
*/
44-
public static function get(string $url): HttpResponseInterface|null
46+
public static function get(string $url): HttpResponseInterface
4547
{
4648
try {
4749
return self::requestor($url, 'GET', self::$optHeaders);
@@ -56,9 +58,11 @@ public static function get(string $url): HttpResponseInterface|null
5658
* @param string $url
5759
* @param array $body
5860
* @param array $headers
59-
* @return object|null
61+
* @return HttpResponseInterface
62+
*
63+
* @throws HttpException
6064
*/
61-
public static function post(string $url, array $body): HttpResponseInterface|null
65+
public static function post(string $url, array $body): HttpResponseInterface
6266
{
6367
try {
6468
return self::requestor($url, 'POST', self::$optHeaders, $body);
@@ -75,7 +79,9 @@ public static function post(string $url, array $body): HttpResponseInterface|nul
7579
* @param string $method
7680
* @param array $headers
7781
* @param array $body
78-
* @return object|null
82+
* @return HttpResponseInterface
83+
*
84+
* @throws HttpException
7985
*/
8086
public static function requestor(
8187
string $url,
@@ -104,14 +110,13 @@ public static function requestor(
104110
);
105111
curl_setopt_array($ch, $curlOptions);
106112

107-
// Get http status code info
108-
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
109-
$statusCode = http_response_code($httpCode);
110-
111113
$response = curl_exec($ch);
112114
curl_close($ch);
113115

114-
return new HttpResponse($response, $statusCode);
116+
// Get http status code info
117+
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
118+
119+
return new HttpResponse($response, $httpCode);
115120

116121
} catch (\Throwable $th) {
117122
throw new HttpException("Error when request API");

0 commit comments

Comments
 (0)