fix: do not JSON parse arbitrary bodies#627
Conversation
Greptile SummaryThis PR fixes a crash that occurred when the WorkOS API returns a non-JSON response body (e.g. a Confidence Score: 5/5Safe to merge; the fix is correct and prior P1 concerns are fully resolved in the current implementation. The only remaining finding is a P2 style suggestion to narrow the except Exception clause to except ValueError. All prior P1 concerns (dead code branch, broken request_raw/request_list) are no longer applicable to the current diff. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[_deserialize_response called] --> B{status 204 or no content?}
B -->|Yes| C[return None]
B -->|No| D[try: data = response.json]
D -->|parse error| E[except Exception: return None]
D -->|success| F{model is not None?}
F -->|Yes| G[return model.from_dict data]
F -->|No| H[return data]
H --> I[request_raw: dict or empty dict]
H --> J[request_list: list or raise WorkOSError]
Reviews (3): Last reviewed commit: "don't lazily shortcut" | Re-trigger Greptile |
|
@greptile review |
The client should not always assume that the API response is going to be JSON.
fixes #626