add crud api global setting and make global api response and handle response web and api on bootstrap app

This commit is contained in:
arifal hidayat
2025-01-27 02:08:40 +07:00
parent 5d0965bd3b
commit f1aa8868be
8 changed files with 95 additions and 27 deletions

View File

@@ -1,11 +1,12 @@
<?php
namespace App;
use App\Helpers\ApiResponse;
use App\Traits\GlobalApiResponse;
use GuzzleHttp\Client;
use Exception;
class ServiceClient
{
use GlobalApiResponse;
private $client;
private $baseUrl;
private $headers;
@@ -41,9 +42,9 @@ class ServiceClient
$response = $this->client->request($method, $this->baseUrl . $url, $options);
$resultResponse = json_decode($response->getBody(), true);
return ApiResponse::successResponse($resultResponse, "Successfully fetched data");
return $this->resSuccess($resultResponse);
} catch (Exception $e) {
return ApiResponse::errorResponse($e->getMessage(), $e->getCode());
return $this->resError($e->getMessage());
}
}