Skip to content

Commit 4dc4e92

Browse files
authored
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
1 parent 5e36552 commit 4dc4e92

File tree

2 files changed

+2
-19
lines changed

2 files changed

+2
-19
lines changed

src/Discord/ApiHelper.php

+2-7
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ public function sendMessage(int $userId, string $message, ?File $file = null): v
6767
],
6868
]);
6969

70-
if (200 !== $response->getStatusCode()) {
71-
throw new \RuntimeException('Failed to create private channel: ' . $response->getContent(false));
72-
}
73-
7470
$channel = $response->toArray();
7571
$channelId = $channel['id'];
7672

@@ -100,9 +96,8 @@ public function sendMessage(int $userId, string $message, ?File $file = null): v
10096
// Send message to the private channel
10197
$response = $this->callApi('POST', "/channels/{$channelId}/messages", $options);
10298

103-
if (200 !== $response->getStatusCode()) {
104-
throw new \RuntimeException('Failed to send private message: ' . $response->getContent(false));
105-
}
99+
// Force http-client to check the response status code
100+
$response->getContent();
106101
}
107102

108103
/**

src/Slack/UserExtractor.php

-12
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use JoliCode\SecretSanta\Model\Group;
1717
use JoliCode\SecretSanta\Model\User;
1818
use JoliCode\Slack\Api\Model\ObjsUser;
19-
use JoliCode\Slack\Exception\SlackErrorResponse;
2019

2120
class UserExtractor
2221
{
@@ -44,17 +43,6 @@ public function extractAll(string $token): array
4443
'limit' => 200,
4544
'cursor' => $cursor,
4645
]);
47-
} catch (SlackErrorResponse $slackErrorResponse) {
48-
if ('ratelimited' === $slackErrorResponse->getErrorCode()) {
49-
sleep(30);
50-
51-
$response = $this->clientFactory->getClientForToken($token)->usersList([
52-
'limit' => 200,
53-
'cursor' => $cursor,
54-
]);
55-
} else {
56-
throw new UserExtractionFailedException(SlackApplication::APPLICATION_CODE, 'Could not fetch members in team.', $slackErrorResponse);
57-
}
5846
} catch (\Throwable $t) {
5947
throw new UserExtractionFailedException(SlackApplication::APPLICATION_CODE, 'Could not fetch members in team.', $t);
6048
}

0 commit comments

Comments
 (0)