Skip to content

Commit

Permalink
Do not catch HTTP exception for Discord to better handle 403 (#309)
Browse files Browse the repository at this point in the history
* Do not catch HTTP exception for Discord to better handle 403

* Remove retry duplicate code for Slack client
  • Loading branch information
pyrech authored Dec 12, 2024
1 parent 5e36552 commit 4dc4e92
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 19 deletions.
9 changes: 2 additions & 7 deletions src/Discord/ApiHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];

Expand Down Expand Up @@ -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();
}

/**
Expand Down
12 changes: 0 additions & 12 deletions src/Slack/UserExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 4dc4e92

Please sign in to comment.