Commit 85ba07a
committed
Fix body reading in logging middleware for non-JSON responses
The logging middleware was calling response.json() and falling back to
response.text() on the same cloned response. This fails when json()
fails to parse (e.g., HTML error pages from Cloudflare) because json()
consumes the body stream even when parsing fails.
Fix: Read as text() first, then try JSON.parse() on the string. This
only consumes the body once and handles non-JSON responses correctly.1 parent 2b4e60a commit 85ba07a
1 file changed
Lines changed: 6 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
165 | 165 | | |
166 | 166 | | |
167 | 167 | | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
168 | 172 | | |
169 | | - | |
| 173 | + | |
170 | 174 | | |
171 | | - | |
| 175 | + | |
172 | 176 | | |
173 | 177 | | |
174 | 178 | | |
| |||
0 commit comments