fix(auth): handle malformed bridge-token responses gracefully#568
fix(auth): handle malformed bridge-token responses gracefully#568RapidPoseidon wants to merge 1 commit intomainfrom
Conversation
`_get_bridge_tokens` only caught `requests.RequestException`, so a response that parsed successfully but was missing `readKey`/`writeKey` (or wasn't JSON at all) raised `KeyError` / `ValueError` and surfaced a confusing traceback at SDK boot time. Catch `ValueError` from `response.json()` and `KeyError`/`TypeError` from the `BridgeToken` construction, log a useful diagnostic (including the keys that *were* present), and return `None` — the caller already treats `None` as the no-auth-available signal and falls through to a readable error path. Session: https://session-bc38cc85.poseidon.rapidata.internal/ Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> Co-Authored-By: lino <lino@rapidata.ai>
Code ReviewOverviewThis PR correctly identifies that What's good
Concerns1.
|
Summary
```python
data = response.json()
return BridgeToken(read_key=data["readKey"], write_key=data["writeKey"])
```
_get_bridge_tokensonly caughtrequests.RequestException. A 200 response with:ValueError(fromresponse.json())readKey/writeKey→KeyErrordatais a list orNone→TypeError…all bubbled up as raw tracebacks out of the first call the user makes.
Fix
Catch
ValueErroron the JSON parse andKeyError/TypeErroron the model construction. Log a diagnostic that includes the keys the server did return, and fall through toreturn None— which the caller already treats as "no bridge token" and reports with a readable message.Test plan
uv run pyright src/rapidata/rapidata_client→ 0 errors🔗 Session: https://session-bc38cc85.poseidon.rapidata.internal/