From 4dc4e9263ecc9048d77a2e57efe52244afb2ce41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFck=20Piera?= Date: Thu, 12 Dec 2024 09:55:22 +0100 Subject: [PATCH] Do not catch HTTP exception for Discord to better handle 403 (#309) * Do not catch HTTP exception for Discord to better handle 403 * Remove retry duplicate code for Slack client --- src/Discord/ApiHelper.php | 9 ++------- src/Slack/UserExtractor.php | 12 ------------ 2 files changed, 2 insertions(+), 19 deletions(-) diff --git a/src/Discord/ApiHelper.php b/src/Discord/ApiHelper.php index 4d052e9..0206258 100644 --- a/src/Discord/ApiHelper.php +++ b/src/Discord/ApiHelper.php @@ -67,10 +67,6 @@ public function sendMessage(int $userId, string $message, ?File $file = null): v ], ]); - if (200 !== $response->getStatusCode()) { - throw new \RuntimeException('Failed to create private channel: ' . $response->getContent(false)); - } - $channel = $response->toArray(); $channelId = $channel['id']; @@ -100,9 +96,8 @@ public function sendMessage(int $userId, string $message, ?File $file = null): v // Send message to the private channel $response = $this->callApi('POST', "/channels/{$channelId}/messages", $options); - if (200 !== $response->getStatusCode()) { - throw new \RuntimeException('Failed to send private message: ' . $response->getContent(false)); - } + // Force http-client to check the response status code + $response->getContent(); } /** diff --git a/src/Slack/UserExtractor.php b/src/Slack/UserExtractor.php index c4cdf1f..0601d50 100644 --- a/src/Slack/UserExtractor.php +++ b/src/Slack/UserExtractor.php @@ -16,7 +16,6 @@ use JoliCode\SecretSanta\Model\Group; use JoliCode\SecretSanta\Model\User; use JoliCode\Slack\Api\Model\ObjsUser; -use JoliCode\Slack\Exception\SlackErrorResponse; class UserExtractor { @@ -44,17 +43,6 @@ public function extractAll(string $token): array 'limit' => 200, 'cursor' => $cursor, ]); - } catch (SlackErrorResponse $slackErrorResponse) { - if ('ratelimited' === $slackErrorResponse->getErrorCode()) { - sleep(30); - - $response = $this->clientFactory->getClientForToken($token)->usersList([ - 'limit' => 200, - 'cursor' => $cursor, - ]); - } else { - throw new UserExtractionFailedException(SlackApplication::APPLICATION_CODE, 'Could not fetch members in team.', $slackErrorResponse); - } } catch (\Throwable $t) { throw new UserExtractionFailedException(SlackApplication::APPLICATION_CODE, 'Could not fetch members in team.', $t); }