How to fix Uncaught Error: Not found
I have this getTeams query:
I receive this error when no teams can be found where the user is also a member.
How can I solve this?
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)
},
})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 clientError: [CONVEX Q(teams:getTeams)] [Request ID: 30092d87adbe25b8] Server Error
Uncaught Error: Not found
at handler (../convex/teams.ts:70:4)
Called by clientHow can I solve this?
