1yangsh opened a new pull request, #77447:
URL: https://github.com/apache/airflow/pull/77447
`MwaaHook` falls back to a local web session token when
`airflow:InvokeRestApi` is denied, or when `generate_local_token=True`. On an
HTTP error it logs the error body before re-raising, but it parses that body
with no guard:
except requests.HTTPError as e:
self.log.error(e.response.json())
raise
The MWAA web server, or a proxy or load balancer in front of it, can answer
with a non-JSON body, for example an HTML 502/504 page or an empty body. Then
`response.json()` raises `JSONDecodeError` inside the handler. That exception
replaces the `HTTPError`, so callers that catch `HTTPError` or check the status
code miss the failure.
This change logs `response.text` when the body is not JSON and re-raises the
original `HTTPError`. It is the same change that was merged for the Dataprep
hook in #71702.
| error body | before | after |
|---|---|---|
| JSON | `HTTPError` | `HTTPError` |
| `<html>502 Bad Gateway</html>` | `JSONDecodeError` | `HTTPError` |
| empty | `JSONDecodeError` | `HTTPError` |
The new test builds a real `requests.Response` with status 502, so
`raise_for_status()` and `json()` behave exactly as in production. It fails on
`main` with `JSONDecodeError` and passes with the fix.
This picks up #71938, which was closed as stale without its tests having
been run.
related: #71938
---
##### Was generative AI tooling used to co-author this PR?
- [X] Yes (please specify the tool below)
Generated-by: Claude Code following [the
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
---
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]