fix: stop double-reporting errors via Log::error in handleException#4
Merged
Merged
Conversation
The Log::error call in handleException caused duplicate error reports in consumers using Bugsnag's Laravel log handler: once from this internal log call (as the original Guzzle ClientException) and again when the caller's queue worker / exception reporter handled the thrown LeverApiException. The thrown LeverApiException already carries statusCode, responseBody, and the original exception as $previous, so callers have everything they need to log or classify the error. Logging is now the caller's responsibility. The wrapped exception message now includes the endpoint for easier debugging without requiring callers to inspect the previous chain. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Removes the
Log::error(..., ['exception' => \$e])call insideLeverClient::handleException(). The thrownLeverApiExceptionalready carriesstatusCode,responseBody, and the original Guzzle exception as\$previous— everything a caller needs to log or classify the error. Logging is now the caller's responsibility.The wrapped exception message also now includes the endpoint (
"HTTP $method $endpoint failed: ...") so callers don't need to inspect the previous chain to identify the failing call.Why this matters
Downstream Laravel apps using Bugsnag (or any monolog handler that promotes the
exceptioncontext to a separate error) were getting two reports per failed Lever request — once from this internalLog::error(grouped asGuzzleHttp\Exception\ClientException) and again when the caller's queue worker / exception reporter handled the propagatedLeverApiException.In one observed production case in the Spot project, this produced 120 + 104 = 224 redundant Bugsnag events for the same handful of permanently-failing job sync attempts.
Notes
LeverApiException extends RuntimeException, so any caller usingcatch (RuntimeException $e)is unaffected."Error executing HTTP $method. Please check the logs for more details."to"HTTP $method $endpoint failed: <original message>". Callers matching on message text would need to update — none in the test suite do.use Illuminate\Support\Facades\Log;import.Test plan
OpportunitiesTest::fail_to_create_opportunity_when_no_perform_as_parameter_includedstill passes viaRuntimeException::classparent match)OpportunitiesTest::client_error_exposes_status_and_response_bodystill validates statusCode/responseBody/previous chainv1.0.11after merge🤖 Generated with Claude Code