From 6c2a3545942f9df739ff88c26a3cc0a7f00f4c5d Mon Sep 17 00:00:00 2001 From: Paulo Castellano Date: Tue, 31 Mar 2026 21:43:30 -0300 Subject: [PATCH] refactor: remove unused context param from handleApiError across all publishers --- app/Services/Social/FacebookPublisher.php | 24 +++++++++---------- app/Services/Social/LinkedInPagePublisher.php | 18 +++++++------- app/Services/Social/LinkedInPublisher.php | 18 +++++++------- app/Services/Social/PinterestPublisher.php | 14 +++++------ app/Services/Social/ThreadsPublisher.php | 14 +++++------ app/Services/Social/TikTokPublisher.php | 8 +++---- app/Services/Social/XPublisher.php | 14 +++++------ 7 files changed, 55 insertions(+), 55 deletions(-) diff --git a/app/Services/Social/FacebookPublisher.php b/app/Services/Social/FacebookPublisher.php index ce0cfa83..55531450 100644 --- a/app/Services/Social/FacebookPublisher.php +++ b/app/Services/Social/FacebookPublisher.php @@ -77,7 +77,7 @@ private function publishTextPost(string $pageId, string $accessToken, string $co 'status' => $response->status(), 'body' => $response->body(), ]); - $this->handleApiError($response, 'Facebook API error'); + $this->handleApiError($response); } $data = $response->json(); @@ -104,7 +104,7 @@ private function publishSingleImagePost(string $pageId, string $accessToken, ?st 'status' => $response->status(), 'body' => $response->body(), ]); - $this->handleApiError($response, 'Facebook API error'); + $this->handleApiError($response); } $data = $response->json(); @@ -170,7 +170,7 @@ private function publishMultiImagePost(string $pageId, string $accessToken, ?str 'status' => $response->status(), 'body' => $response->body(), ]); - $this->handleApiError($response, 'Facebook API error'); + $this->handleApiError($response); } $data = $response->json(); @@ -198,7 +198,7 @@ private function publishVideoPost(string $pageId, string $accessToken, ?string $ 'status' => $response->status(), 'body' => $response->body(), ]); - $this->handleApiError($response, 'Facebook API error'); + $this->handleApiError($response); } $data = $response->json(); @@ -225,7 +225,7 @@ private function publishReel(string $pageId, string $accessToken, ?string $conte 'status' => $response->status(), 'body' => $response->body(), ]); - $this->handleApiError($response, 'Facebook API error'); + $this->handleApiError($response); } $data = $response->json(); @@ -242,7 +242,7 @@ private function publishReel(string $pageId, string $accessToken, ?string $conte Log::error('Facebook reel upload transfer failed', [ 'body' => $uploadResponse->body(), ]); - $this->handleApiError($uploadResponse, 'Facebook API error'); + $this->handleApiError($uploadResponse); } // Finish and publish the reel @@ -258,7 +258,7 @@ private function publishReel(string $pageId, string $accessToken, ?string $conte Log::error('Facebook reel finish failed', [ 'body' => $finishResponse->body(), ]); - $this->handleApiError($finishResponse, 'Facebook API error'); + $this->handleApiError($finishResponse); } $finishData = $finishResponse->json(); @@ -284,7 +284,7 @@ private function publishStory(string $pageId, string $accessToken, $media): arra ]); if ($response->failed()) { - $this->handleApiError($response, 'Facebook API error'); + $this->handleApiError($response); } $videoId = $response->json()['video_id']; @@ -304,7 +304,7 @@ private function publishStory(string $pageId, string $accessToken, $media): arra ]); if ($finishResponse->failed()) { - $this->handleApiError($finishResponse, 'Facebook API error'); + $this->handleApiError($finishResponse); } $storyId = $finishResponse->json()['post_id'] ?? $videoId; @@ -325,7 +325,7 @@ private function publishStory(string $pageId, string $accessToken, $media): arra Log::error('Facebook photo story failed', [ 'body' => $response->body(), ]); - $this->handleApiError($response, 'Facebook API error'); + $this->handleApiError($response); } $storyId = $response->json()['post_id'] ?? $response->json()['id']; @@ -345,13 +345,13 @@ private function uploadUnpublishedPhoto(string $pageId, string $accessToken, $me ]); if ($response->failed()) { - $this->handleApiError($response, 'Facebook API error'); + $this->handleApiError($response); } return $response->json()['id']; } - private function handleApiError(Response $response, string $context): void + private function handleApiError(Response $response): never { throw FacebookPublishException::fromApiResponse($response); } diff --git a/app/Services/Social/LinkedInPagePublisher.php b/app/Services/Social/LinkedInPagePublisher.php index 21c5575c..a1ce5cb6 100644 --- a/app/Services/Social/LinkedInPagePublisher.php +++ b/app/Services/Social/LinkedInPagePublisher.php @@ -132,7 +132,7 @@ private function publishPost(string $organizationUrn, ?string $content, $media, 'status' => $response->status(), 'body' => $response->body(), ]); - $this->handleApiError($response, 'LinkedIn Page API error'); + $this->handleApiError($response); } $postId = $response->header('x-restli-id'); @@ -205,7 +205,7 @@ private function publishCarousel(string $organizationUrn, ?string $content, $med 'status' => $response->status(), 'body' => $response->body(), ]); - $this->handleApiError($response, 'LinkedIn Page API error'); + $this->handleApiError($response); } $postId = $response->header('x-restli-id'); @@ -264,7 +264,7 @@ private function uploadImage($mediaItem, string $ownerUrn): ?string if ($initResponse->failed()) { Log::error('LinkedIn Page image init failed', ['body' => $initResponse->body()]); - $this->handleApiError($initResponse, 'Failed to initialize LinkedIn Page image upload'); + $this->handleApiError($initResponse); } $initData = $initResponse->json(); @@ -302,7 +302,7 @@ private function uploadImage($mediaItem, string $ownerUrn): ?string if ($uploadResponse->failed()) { Log::error('LinkedIn Page image upload failed', ['body' => $uploadResponse->body()]); - $this->handleApiError($uploadResponse, 'Failed to upload LinkedIn Page image'); + $this->handleApiError($uploadResponse); } Log::info('LinkedIn Page image upload success', ['imageUrn' => $imageUrn]); @@ -348,7 +348,7 @@ private function doUploadVideo(string $tempFile, $mediaItem, string $ownerUrn): if ($initResponse->failed()) { Log::error('LinkedIn Page video init failed', ['body' => $initResponse->body()]); - $this->handleApiError($initResponse, 'Failed to initialize LinkedIn Page video upload'); + $this->handleApiError($initResponse); } $initData = $initResponse->json(); @@ -399,7 +399,7 @@ private function doUploadVideo(string $tempFile, $mediaItem, string $ownerUrn): 'index' => $index, 'body' => $chunkResponse->body(), ]); - $this->handleApiError($chunkResponse, 'Failed to upload LinkedIn Page video chunk'); + $this->handleApiError($chunkResponse); } $etag = $chunkResponse->header('etag'); @@ -424,7 +424,7 @@ private function doUploadVideo(string $tempFile, $mediaItem, string $ownerUrn): if ($finalizeResponse->failed()) { Log::error('LinkedIn Page video finalize failed', ['body' => $finalizeResponse->body()]); - $this->handleApiError($finalizeResponse, 'Failed to finalize LinkedIn Page video upload'); + $this->handleApiError($finalizeResponse); } Log::info('LinkedIn Page video upload finalized', ['videoUrn' => $videoUrn]); @@ -483,7 +483,7 @@ private function refreshToken(SocialAccount $account): void ]); if ($response->failed()) { - $this->handleApiError($response, 'Failed to refresh LinkedIn Page token'); + $this->handleApiError($response); } $data = $response->json(); @@ -498,7 +498,7 @@ private function refreshToken(SocialAccount $account): void app(LinkedInTokenSynchronizer::class)->syncTokens($account); } - private function handleApiError(Response $response, string $context): void + private function handleApiError(Response $response): never { throw LinkedInPublishException::fromApiResponse($response); } diff --git a/app/Services/Social/LinkedInPublisher.php b/app/Services/Social/LinkedInPublisher.php index 23dd3d5d..be659ca1 100644 --- a/app/Services/Social/LinkedInPublisher.php +++ b/app/Services/Social/LinkedInPublisher.php @@ -125,7 +125,7 @@ private function publishPost(string $personUrn, ?string $content, $media): array 'status' => $response->status(), 'body' => $response->body(), ]); - $this->handleApiError($response, 'LinkedIn API error'); + $this->handleApiError($response); } $postId = $response->header('x-restli-id'); @@ -192,7 +192,7 @@ private function publishCarousel(string $personUrn, ?string $content, $mediaColl 'status' => $response->status(), 'body' => $response->body(), ]); - $this->handleApiError($response, 'LinkedIn API error'); + $this->handleApiError($response); } $postId = $response->header('x-restli-id'); @@ -245,7 +245,7 @@ private function uploadImage($mediaItem, string $ownerUrn): ?string if ($initResponse->failed()) { Log::error('LinkedIn image init failed', ['body' => $initResponse->body()]); - $this->handleApiError($initResponse, 'Failed to initialize LinkedIn image upload'); + $this->handleApiError($initResponse); } $initData = $initResponse->json(); @@ -283,7 +283,7 @@ private function uploadImage($mediaItem, string $ownerUrn): ?string if ($uploadResponse->failed()) { Log::error('LinkedIn image upload failed', ['body' => $uploadResponse->body()]); - $this->handleApiError($uploadResponse, 'Failed to upload LinkedIn image'); + $this->handleApiError($uploadResponse); } Log::info('LinkedIn image upload success', ['imageUrn' => $imageUrn]); @@ -329,7 +329,7 @@ private function doUploadVideo(string $tempFile, $mediaItem, string $ownerUrn): if ($initResponse->failed()) { Log::error('LinkedIn video init failed', ['body' => $initResponse->body()]); - $this->handleApiError($initResponse, 'Failed to initialize LinkedIn video upload'); + $this->handleApiError($initResponse); } $initData = $initResponse->json(); @@ -380,7 +380,7 @@ private function doUploadVideo(string $tempFile, $mediaItem, string $ownerUrn): 'index' => $index, 'body' => $chunkResponse->body(), ]); - $this->handleApiError($chunkResponse, 'Failed to upload LinkedIn video chunk'); + $this->handleApiError($chunkResponse); } $etag = $chunkResponse->header('etag'); @@ -405,7 +405,7 @@ private function doUploadVideo(string $tempFile, $mediaItem, string $ownerUrn): if ($finalizeResponse->failed()) { Log::error('LinkedIn video finalize failed', ['body' => $finalizeResponse->body()]); - $this->handleApiError($finalizeResponse, 'Failed to finalize LinkedIn video upload'); + $this->handleApiError($finalizeResponse); } Log::info('LinkedIn video upload finalized', ['videoUrn' => $videoUrn]); @@ -464,7 +464,7 @@ private function refreshToken(SocialAccount $account): void ]); if ($response->failed()) { - $this->handleApiError($response, 'Failed to refresh LinkedIn token'); + $this->handleApiError($response); } $data = $response->json(); @@ -479,7 +479,7 @@ private function refreshToken(SocialAccount $account): void app(LinkedInTokenSynchronizer::class)->syncTokens($account); } - private function handleApiError(Response $response, string $context): void + private function handleApiError(Response $response): never { throw LinkedInPublishException::fromApiResponse($response); } diff --git a/app/Services/Social/PinterestPublisher.php b/app/Services/Social/PinterestPublisher.php index 1f7734f8..27468ff4 100644 --- a/app/Services/Social/PinterestPublisher.php +++ b/app/Services/Social/PinterestPublisher.php @@ -108,7 +108,7 @@ private function publishImagePin(PostPlatform $postPlatform): array 'status' => $response->status(), 'body' => $response->body(), ]); - $this->handleApiError($response, 'Pinterest API error'); + $this->handleApiError($response); } $data = $response->json(); @@ -152,7 +152,7 @@ private function publishVideoPin(PostPlatform $postPlatform): array 'status' => $registerResponse->status(), 'body' => $registerResponse->body(), ]); - $this->handleApiError($registerResponse, 'Pinterest media registration error'); + $this->handleApiError($registerResponse); } $registerData = $registerResponse->json(); @@ -246,7 +246,7 @@ private function publishVideoPin(PostPlatform $postPlatform): array 'status' => $response->status(), 'body' => $response->body(), ]); - $this->handleApiError($response, 'Pinterest API error'); + $this->handleApiError($response); } $data = $response->json(); @@ -312,7 +312,7 @@ private function publishCarousel(PostPlatform $postPlatform): array 'status' => $response->status(), 'body' => $response->body(), ]); - $this->handleApiError($response, 'Pinterest API error'); + $this->handleApiError($response); } $data = $response->json(); @@ -382,7 +382,7 @@ public function refreshToken(SocialAccount $account): void if ($response->failed()) { Log::error('Pinterest token refresh failed', ['body' => $response->body()]); - $this->handleApiError($response, 'Failed to refresh Pinterest token'); + $this->handleApiError($response); } $data = $response->json(); @@ -413,13 +413,13 @@ public function getBoards(SocialAccount $account): array if ($response->failed()) { Log::error('Pinterest get boards failed', ['body' => $response->body()]); - $this->handleApiError($response, 'Pinterest API error'); + $this->handleApiError($response); } return $response->json()['items'] ?? []; } - private function handleApiError(Response $response, string $context): void + private function handleApiError(Response $response): never { throw PinterestPublishException::fromApiResponse($response); } diff --git a/app/Services/Social/ThreadsPublisher.php b/app/Services/Social/ThreadsPublisher.php index 33fad995..2105c525 100644 --- a/app/Services/Social/ThreadsPublisher.php +++ b/app/Services/Social/ThreadsPublisher.php @@ -68,7 +68,7 @@ private function publishTextPost(string $userId, string $accessToken, string $co 'status' => $containerResponse->status(), 'body' => $containerResponse->body(), ]); - $this->handleApiError($containerResponse, 'Threads API error'); + $this->handleApiError($containerResponse); } $containerId = $containerResponse->json()['id']; @@ -92,7 +92,7 @@ private function publishImagePost(string $userId, string $accessToken, ?string $ 'status' => $containerResponse->status(), 'body' => $containerResponse->body(), ]); - $this->handleApiError($containerResponse, 'Threads API error'); + $this->handleApiError($containerResponse); } $containerId = $containerResponse->json()['id']; @@ -123,7 +123,7 @@ private function publishVideoPost(string $userId, string $accessToken, ?string $ 'status' => $containerResponse->status(), 'body' => $containerResponse->body(), ]); - $this->handleApiError($containerResponse, 'Threads API error'); + $this->handleApiError($containerResponse); } $containerId = $containerResponse->json()['id']; @@ -195,7 +195,7 @@ private function publishCarousel(string $userId, string $accessToken, ?string $c Log::error('Threads carousel container creation failed', [ 'body' => $carouselResponse->body(), ]); - $this->handleApiError($carouselResponse, 'Threads API error'); + $this->handleApiError($carouselResponse); } $carouselId = $carouselResponse->json()['id']; @@ -216,7 +216,7 @@ private function publishContainer(string $userId, string $accessToken, string $c 'status' => $publishResponse->status(), 'body' => $publishResponse->body(), ]); - $this->handleApiError($publishResponse, 'Threads publish error'); + $this->handleApiError($publishResponse); } $mediaId = $publishResponse->json()['id']; @@ -292,7 +292,7 @@ private function refreshToken(SocialAccount $account): void if ($response->failed()) { Log::error('Threads token refresh failed', ['body' => $response->body()]); - $this->handleApiError($response, 'Failed to refresh Threads token'); + $this->handleApiError($response); } $data = $response->json(); @@ -308,7 +308,7 @@ private function refreshToken(SocialAccount $account): void Log::info('Threads token refreshed successfully'); } - private function handleApiError(Response $response, string $context): void + private function handleApiError(Response $response): never { throw ThreadsPublishException::fromApiResponse($response); } diff --git a/app/Services/Social/TikTokPublisher.php b/app/Services/Social/TikTokPublisher.php index 2a8835d5..df47c19a 100644 --- a/app/Services/Social/TikTokPublisher.php +++ b/app/Services/Social/TikTokPublisher.php @@ -121,7 +121,7 @@ private function publishVideo(PostPlatform $postPlatform, $media): array 'status' => $response->status(), 'body' => $response->body(), ]); - $this->handleApiError($response, 'TikTok API error'); + $this->handleApiError($response); } $data = $response->json(); @@ -184,7 +184,7 @@ private function publishPhotos(PostPlatform $postPlatform, $mediaCollection): ar 'status' => $response->status(), 'body' => $response->body(), ]); - $this->handleApiError($response, 'TikTok API error'); + $this->handleApiError($response); } $data = $response->json(); @@ -277,7 +277,7 @@ private function refreshToken(SocialAccount $account): void if ($response->failed()) { Log::error('TikTok token refresh failed', ['body' => $response->body()]); - $this->handleApiError($response, 'Failed to refresh TikTok token'); + $this->handleApiError($response); } $data = $response->json(); @@ -291,7 +291,7 @@ private function refreshToken(SocialAccount $account): void Log::info('TikTok token refreshed successfully'); } - private function handleApiError(Response $response, string $context): void + private function handleApiError(Response $response): never { throw TikTokPublishException::fromApiResponse($response); } diff --git a/app/Services/Social/XPublisher.php b/app/Services/Social/XPublisher.php index c4c71903..351a6254 100644 --- a/app/Services/Social/XPublisher.php +++ b/app/Services/Social/XPublisher.php @@ -81,7 +81,7 @@ public function publish(PostPlatform $postPlatform): array 'status' => $response->status(), 'body' => $response->body(), ]); - $this->handleApiError($response, 'X API error'); + $this->handleApiError($response); } $responseData = $response->json(); @@ -156,7 +156,7 @@ private function uploadMedia($mediaItem): ?array 'status' => $response->status(), 'body' => $response->body(), ]); - $this->handleApiError($response, 'Failed to upload media'); + $this->handleApiError($response); } $responseData = $response->json(); @@ -195,7 +195,7 @@ private function chunkedUpload(string $tempFile, int $totalBytes, string $mimeTy 'status' => $initResponse->status(), 'body' => $initResponse->body(), ]); - $this->handleApiError($initResponse, 'Failed to initialize chunked upload'); + $this->handleApiError($initResponse); } $initData = $initResponse->json(); @@ -238,7 +238,7 @@ private function chunkedUpload(string $tempFile, int $totalBytes, string $mimeTy 'body' => $appendResponse->body(), 'segment' => $index, ]); - $this->handleApiError($appendResponse, 'Failed to append chunk'); + $this->handleApiError($appendResponse); } $index++; @@ -258,7 +258,7 @@ private function chunkedUpload(string $tempFile, int $totalBytes, string $mimeTy 'status' => $finalizeResponse->status(), 'body' => $finalizeResponse->body(), ]); - $this->handleApiError($finalizeResponse, 'Failed to finalize chunked upload'); + $this->handleApiError($finalizeResponse); } $finalizeData = $finalizeResponse->json(); @@ -348,7 +348,7 @@ private function refreshToken(SocialAccount $account): void ]); if ($response->failed()) { - $this->handleApiError($response, 'Failed to refresh X token'); + $this->handleApiError($response); } $data = $response->json(); @@ -360,7 +360,7 @@ private function refreshToken(SocialAccount $account): void ]); } - private function handleApiError(Response $response, string $context): void + private function handleApiError(Response $response): never { throw XPublishException::fromApiResponse($response); }