Description
Frontend error handling fails when the response object is undefined.
Additionally, the current handling appears to call .json() without validating whether the response actually contains application/json.
Expected Behavior
- Undefined response objects are handled safely.
.json() is only called for JSON responses.
- Non-JSON responses are handled via
.text() or another suitable fallback.
- The original error should remain visible and understandable.
Observed Behavior
The frontend throws:
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'json')
at index-*.js:4232:86238
This indicates that .json() is called on an undefined value.
There also appears to be no content-type check before parsing the response as JSON.
Technical Notes
Current behavior likely assumes a valid JSON response object:
Safer handling should validate both the response and the content type:
if (!response) {
throw new Error("No response object available");
}
const contentType = response.headers?.get("content-type") || "";
const payload = contentType.includes("application/json")
? await response.json()
: await response.text();
Acceptance Criteria
- No
.json() call is made on an undefined response.
- JSON parsing only happens for responses with JSON content type.
- Non-JSON responses are handled without throwing parser-related errors.
- The original request or backend error remains debuggable.
Description
Frontend error handling fails when the response object is
undefined.Additionally, the current handling appears to call
.json()without validating whether the response actually containsapplication/json.Expected Behavior
.json()is only called for JSON responses..text()or another suitable fallback.Observed Behavior
The frontend throws:
This indicates that
.json()is called on an undefined value.There also appears to be no content-type check before parsing the response as JSON.
Technical Notes
Current behavior likely assumes a valid JSON response object:
Safer handling should validate both the response and the content type:
Acceptance Criteria
.json()call is made on an undefined response.