MathiasM
Convex Community2y ago
5 replies
Mathias

How to fix Uncaught Error: Not found

I have this getTeams query:

export const getTeams = query({
  handler: async (ctx) => {
    const identity = await ctx.auth.getUserIdentity()

    if (!identity) {
      throw new Error("Unauthenticated")
    }

    const userId = identity.subject

    const user = await ctx.db
      .query("users")
      .withIndex("by_user", (q) => q.eq("userId", userId))
      .first()

    if (!user) {
      throw new Error("Not found")
    }

    const teamIds = await ctx.db
      .query("teamMembers")
      .withIndex("by_user", (q) => q.eq("userId", user._id))
      .collect()

    const teams = await Promise.all(
      teamIds.map((id) => ctx.db.get(id.teamId as Id<"teams">))
    )

    return teams.filter((team) => team !== null)
  },
})


I receive this error when no teams can be found where the user is also a member.

Error: [CONVEX Q(teams:getTeams)] [Request ID: 30092d87adbe25b8] Server Error
Uncaught Error: Not found
    at handler (../convex/teams.ts:70:4)

  Called by client


How can I solve this?
Was this page helpful?