Skip to content

Commit

Permalink
Update GemRequest.php
Browse files Browse the repository at this point in the history
  • Loading branch information
secure73 authored Jan 31, 2024
1 parent 54f0731 commit 28588dd
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/http/GemRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ public function forwardToRemoteApi(string $remoteApiUrl): JsonResponse
{
$jsonResponse = new JsonResponse();
$ch = curl_init($remoteApiUrl);
if($ch === false)
{
$jsonResponse->create(500, [], 0, "remote api $remoteApiUrl is not responding");
return $jsonResponse;
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->post);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
Expand All @@ -122,13 +127,18 @@ public function forwardToRemoteApi(string $remoteApiUrl): JsonResponse
}
$response = curl_exec($ch);
curl_close($ch);
if(!$response)
if(!$response || !is_string($response))
{
$jsonResponse->create(500, [], 0, 'remote api is not responding');
return $jsonResponse;
}
}
if(!JsonHelper::validateJson($response))
{
$jsonResponse->create(500, [], 0, 'remote api is not responding with valid json');
return $jsonResponse;
}
$response = json_decode($response);
//var_dump($response);
/**@phpstan-ignore-next-line */
$jsonResponse->create($response->http_response_code, $response->data, $response->count, $response->service_message);
return $jsonResponse;
}
Expand Down

0 comments on commit 28588dd

Please sign in to comment.