AOSSIE-Org / AOSSIE-Org/DebateAI
Frontend crashes when backend returns non-JSON or empty responses
- Dominant language
- TypeScript
- Stars
- 84
- Forks
- 198
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 30
Description
### **_Problem_**
The frontend assumes that all API responses are valid JSON and directly calls `response.json()` without validation.
When the backend returns an empty response body or a non-JSON response (for example during authentication failures or server-side errors), the frontend crashes with the following error:
### **_Expected Behavior_**
The frontend should handle error responses gracefully and avoid crashing when the response body is empty or not valid JSON.
Instead, it should:
- Safely parse responses
- Display a user-friendly error message
- Allow the application to continue running
### **_Actual Behavior_**
The frontend crashes immediately when response.json() is called on an empty or invalid response body, making the application unusable.
### **_Impact:_**
Poor user experience
Application crashes instead of showing meaningful errors
Backend issues are masked by frontend runtime errors
New users and contributors cannot proceed when an API error occurs
### **_Steps to Reproduce:_**
Run the backend and frontend locally
Trigger an API error (e.g. auth failure or backend returning an empty response)
Observe the frontend crash with Unexpected end of JSON input
### **_Suggested Fix_**
Before calling response.json(), the frontend should:
_- Check response.ok_
_- Gracefully fall back to response.text() when JSON parsing fails_
_- Handle empty responses safely_
_- This would make the frontend more robust even when backend errors occur.__
Related Issues
This issue is exposed by backend auth failures (see issue #243), but frontend error handling should be improved independently to prevent crashes.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by locating the frontend API call sites that directly invoke response.json(), then reproduce the issue with an authentication failure or empty backend response. Verify the existing response handling and identify how user-facing errors are displayed. Done means invalid or empty responses no longer crash the application, errors are understandable, and normal frontend operation continues.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100