Skip to content

Commit

Permalink
Add a debug log for unrecoverable errors, use constant
Browse files Browse the repository at this point in the history
- The log part will is already partly covered by the  `ApHttpClient::logRequestException` method, but it will be helpful regardless
- use a constant for the 429 rate limited http status code
  • Loading branch information
BentiGorlich committed Nov 24, 2024
1 parent 9bc4daa commit e7a5a53
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/MessageHandler/ActivityPub/Outbox/DeliverHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#[AsMessageHandler]
class DeliverHandler extends MbinMessageHandler
{
public const HTTP_RESPONSE_CODE_RATE_LIMITED = 429;

public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly ApHttpClient $client,
Expand Down Expand Up @@ -59,10 +61,15 @@ public function workWrapper(MessageInterface $message): void
$this->doWork($message);
$conn->commit();
} catch (InvalidApPostException $e) {
if (400 <= $e->responseCode && 500 > $e->responseCode && 429 !== $e->responseCode) {
if (400 <= $e->responseCode && 500 > $e->responseCode && self::HTTP_RESPONSE_CODE_RATE_LIMITED !== $e->responseCode) {
$conn->rollBack();
$this->logger->debug('{domain} responded with {code} for our request, rolling back the changes and not trying again, request: {body}', [
'domain' => $e->url,
'code' => $e->responseCode,
'body' => $e->payload,
]);
throw new UnrecoverableMessageHandlingException('There is a problem with the request which will stay the same, so discarding', previous: $e);
} elseif (429 === $e->responseCode) {
} elseif (self::HTTP_RESPONSE_CODE_RATE_LIMITED === $e->responseCode) {
$conn->rollBack();
// a rate limit is always recoverable
throw new RecoverableMessageHandlingException(previous: $e);
Expand Down

0 comments on commit e7a5a53

Please sign in to comment.