Skip to content

customAction fetch request handling #61

Description

@akelch

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:

response.json()

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions