fix: clear errors for connection, auth, and API failures#28
Merged
Conversation
A misconfigured client surfaced a raw httpx error that never mentioned Lightdash (e.g. `httpx.ConnectError: nodename nor servname provided`). `_make_request` now translates the two reported failure modes into descriptive, catchable exceptions — without touching the existing API-error handling: - Transport failures (DNS, refused connection, timeout) -> LightdashConnectionError, naming instance_url and the likely cause. - HTTP 401/403 -> LightdashAuthError, pointing at the access_token. Both subclass LightdashError so existing handlers keep working, and the original httpx error is chained as __cause__. The raise_for_status path and structured error handling are unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
70a0b85 to
2def22d
Compare
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.
Closes #1
Problem
A misconfigured client surfaced a raw, Lightdash-agnostic error that gave no hint at the cause:
Change (intentionally minimal)
A nested
tryaround just the request translates the two reported failure modes into clear, catchable exceptions. The existingraise_for_status+ structured-error handling is left completely untouched (unchanged context in the diff):LightdashConnectionErrorinstance_url+ likely causeLightdashAuthErroraccess_tokenBoth subclass
LightdashError, so existingexcept LightdashErrorhandlers keep working, and the originalhttpxerror is chained as__cause__.Production diff is +61/−9 across 3 files;
client.pyis +37/−9, all additive around the request — no change to the success path or the existing API-error path.Verified live (the issue's two exact cases)
Tests
tests/test_client_errors.py(8): connect-error wrapping, timeout wrapping,LightdashErrorsubclassing, cause-chaining, 401/403 → auth error, plus two guard tests that the existing structured-error and success paths are unchanged. Full unit suite green (131 passed).