Skip to content

Fix potential TypeError and unhandled exceptions in /create_invite_link route #234

Description

@akil9979

Problem

The /create_invite_link API assumes that the inviter always exists and has an invites array.

If checkInviteLink() returns an empty result, the code tries to access:

response[0].invites

which causes:

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

Invalid inviter_id or server_id values can also cause MongoDB errors.

Expected Behavior

  • Invalid IDs should return a proper error.
  • Missing inviter data should be handled safely.
  • The API should not crash when no invite data exists.

Suggested Fix

  • Validate inviter_id and server_id.
  • Check if response is empty before accessing response[0].invites.
  • Wrap database operations in try/catch to handle errors gracefully.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions