Skip to content

Commit

Permalink
improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
fokosun committed Oct 11, 2023
1 parent 369933a commit 60cc106
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions app/Http/Clients/TikTokHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function getAccessToken(string $code)
return $decoded;
}

public function getUserInfo(string $access_token)
public function getUserInfo(string $access_token): array
{
return $this->makeHttpRequest(
AllowedHttpMethod::GET,
Expand All @@ -65,11 +65,10 @@ public function listVideos(TikTokUserDto $userDto): array
);
}

private function makeHttpRequest(AllowedHttpMethod $httpMethod, $fields = [], $headers = [])
private function makeHttpRequest(AllowedHttpMethod $httpMethod, $fields = [], $headers = []): array
{
$options = ['headers' => ['Content-Type' => 'application/json']];
$v2DisplayApiEndpoint = $this->getV2DisplayApiEndpoint();
$response = [];

if ($bearer = Arr::get($headers, 'Authorization')) {
$options['headers']['Authorization'] = 'Bearer ' . $bearer;
Expand All @@ -81,10 +80,7 @@ private function makeHttpRequest(AllowedHttpMethod $httpMethod, $fields = [], $h

try {
$response = $this->client->request($httpMethod->value, $v2DisplayApiEndpoint, $options);

if ($response->getBody()->getContents() != '') {
$response = $response->getBody()->getContents();
}
return json_decode($response->getBody()->getContents(), true);
} catch (\Exception $exception) {
Log::debug(
'Tiktok: error retrieving user info or listing videos',
Expand All @@ -94,10 +90,8 @@ private function makeHttpRequest(AllowedHttpMethod $httpMethod, $fields = [], $h
]
);

$response['_error'] = $exception->getMessage();
return [];
}

return json_decode($response, true);
}

private function getV1BaseUri(): string
Expand Down

0 comments on commit 60cc106

Please sign in to comment.