-
Notifications
You must be signed in to change notification settings - Fork 199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
show full HTTP response on failure (Feat/1605) #1895
base: devel
Are you sure you want to change the base?
show full HTTP response on failure (Feat/1605) #1895
Conversation
✅ Deploy Preview for dlt-hub-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
I propose an alternative solution to logging the full HTTP response on error: we can use a context manager Example: import dlt
from dlt.sources.helpers.rest_client import paginate, catch_http_error
@dlt.resource(
table_name="issues",
write_disposition="replace",
primary_key="id",
)
def get_issues():
for page in paginate(
"https://api.github.com/repos/dlt-hub/dlt/issues",
headers={"Authorization": "Bearer invalid_token_here"},
):
yield page
pipeline = dlt.pipeline(
pipeline_name="github_issues_merge",
destination="duckdb",
)
with catch_http_error() as http_error:
load_info = pipeline.run(get_issues)
if http_error:
print(f"HTTP {http_error.response.status_code}: {http_error.response.content}") Pros:
The rationale is that in my opinion accessing the HTTPError should be done on the higher level of abstraction than Requests's session as when the user is using the request/response directly they already have easy access to HTTP errors. |
Description
This PR implements error logging of the full HTTP response on error when the
dlt.sources.helpers.requests.Session
is used.Unless a custom session with different configuration is used, all HTTP responses with an error code 4xx will log an error.
This includes:
RESTClient
dlt.sources.rest_api
Related Issues