Skip to content

Commit

Permalink
Added specific log message when HTTP 429 returned from error reportin…
Browse files Browse the repository at this point in the history
…g URL
  • Loading branch information
asgrim committed Jan 11, 2022
1 parent 727ce10 commit 000bdce
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Errors/ScoutClient/HttpErrorReportingClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ final class HttpErrorReportingClient implements ErrorReportingClient
private const SCOUT_REPORTING_PATH = '/apps/error.scout';

private const SCOUT_ACCEPTED_STATUS_CODE = 202;
private const SCOUT_TOO_MANY_REQUESTS = 429;

/** @var ClientInterface */
private $client;
Expand Down Expand Up @@ -93,6 +94,18 @@ public function sendErrorToScout(array $errorEvents): void
}

$statusCode = $response->getStatusCode();

if ($statusCode === self::SCOUT_TOO_MANY_REQUESTS) {
$this->logger->notice(
sprintf(
'Error send limit has been reached (HTTP %d returned from Error reporting service',
self::SCOUT_TOO_MANY_REQUESTS
)
);

return;
}

if ($statusCode !== self::SCOUT_ACCEPTED_STATUS_CODE) {
$this->logger->info(
sprintf('ErrorEvent sending returned unexpected status code %d', $statusCode),
Expand Down
24 changes: 24 additions & 0 deletions tests/Unit/Errors/ScoutClient/HttpErrorReportingClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,30 @@ public function testSendingErrorToScoutLogsFailureToInfo(): void
self::assertTrue($this->logger->hasInfoThatContains('ErrorEvent sending returned unexpected status code 500'));
}

public function testSendingErrorWhenErrorLimitReachedLogsMessage(): void
{
$errorEvent = ErrorEvent::fromThrowable(
Request::fromConfigAndOverrideTime(
$this->createMock(Superglobals::class),
$this->config,
$this->createMock(FindRequestHeaders::class)
),
new RuntimeException('things')
);

$this->client
->expects(self::once())
->method('sendRequest')
->with(self::isInstanceOf(RequestInterface::class))
->willReturn(
(new Psr17Factory())->createResponse(429)
);

$this->errorReportingClient->sendErrorToScout([$errorEvent]);

self::assertTrue($this->logger->hasNoticeThatContains('Error send limit has been reached (HTTP 429 returned from Error reporting service'));
}

public function testSendingErrorToScoutLogsClientExceptionInfo(): void
{
$errorEvent = ErrorEvent::fromThrowable(
Expand Down

0 comments on commit 000bdce

Please sign in to comment.