Skip to content

[BUG] Dashboard crash: 401 API errors causing client-side exception (Cannot read properties of undefined (reading 'map')) #4

@youngcoder45

Description

@youngcoder45

The dashboard crashes with a client-side exception when loading the server settings page.
The browser console shows multiple 401 Unauthorized and 400 Bad Request responses from the API, which results in the frontend attempting to access undefined data.

This eventually triggers the following error:

TypeError: Cannot read properties of undefined (reading 'map')

Because the frontend expects data from the API but receives an error response instead.

Console Errors

Failed to load resource: the server responded with a status of 401 ()
SWR Error for /api/server/{serverId}/stats: Error: Failed to fetch
/api/server/{serverId}/guild-data: Failed to load resource: the server responded with a status of 401 ()

TypeError: Cannot read properties of undefined (reading 'map')
    at settings-66df800ede93c48c.js

Steps to Reproduce

  1. Open the Miku dashboard
  2. Navigate to a server settings page
  3. Open browser developer console
  4. Observe the API errors and client-side crash

Expected Behavior

  • API should return valid authenticated responses
  • Frontend should gracefully handle API errors
  • Dashboard should not crash even if API fails

Actual Behavior

  • API returns 401 Unauthorized
  • Frontend receives undefined data
  • React component attempts to call .map() on undefined
  • Dashboard throws a client-side exception and crashes

Screenshot

Attach screenshot of the console errors and dashboard crash.

Image

Possible Causes

  • Authentication token not being sent in API requests
  • Session expiration or invalid OAuth token
  • API authorization middleware rejecting requests
  • Frontend not validating API response before rendering

Suggested Fix

Add a safe check before mapping data in the frontend:

const items = data?.items || [];
items.map(...)

Or:

if (!data) return null;

Also ensure the API request includes authentication headers.

Environment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions