Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not catch HTTP exception for Discord to better handle 403 #309

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading