no-floating-promises error when using TRPC query.

I have this query using TRPC but am getting the following error. I feel like I should be resolving the prommis and don't get why this is happening. At a quick glance can anyone give some guidance?
Error: Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator. @typescript-eslint/no-floating-promises
Error: Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator. @typescript-eslint/no-floating-promises
add_session: publicProcedure
.query( async ({ctx}) => {
try {
const existing_ip_address = await ctx.prisma.ip_address.findFirst({
where: {
ipAddress: ctx.userData['Ip'] as string,
},
});
if (existing_ip_address) {
console.log('IP address already exists', existing_ip_address);
} else {
const new_ip_address = await ctx.prisma.ip_address.create({
data: {
ipAddress: ctx.userData['Ip'] as string,
}
});
console.log('New IP address added to DB:', new_ip_address);
}
const db_ip = await ctx.prisma.ip_address.findMany({
where: { ipAddress: ctx.userData['Ip'] as string },
});
if (db_ip) {
console.log(db_ip);
const create_session = await ctx.prisma.web_session.create({
data: {
ipAddress: {
connect: { id: db_ip[0]['id'] },
},
userAgent: ctx.userData['user_agent'] as string,
},
});
return create_session;
}
} catch (error) {
console.log("error could not add session to db");
throw error;
} finally {
ctx.prisma.$disconnect();
}
}),
add_session: publicProcedure
.query( async ({ctx}) => {
try {
const existing_ip_address = await ctx.prisma.ip_address.findFirst({
where: {
ipAddress: ctx.userData['Ip'] as string,
},
});
if (existing_ip_address) {
console.log('IP address already exists', existing_ip_address);
} else {
const new_ip_address = await ctx.prisma.ip_address.create({
data: {
ipAddress: ctx.userData['Ip'] as string,
}
});
console.log('New IP address added to DB:', new_ip_address);
}
const db_ip = await ctx.prisma.ip_address.findMany({
where: { ipAddress: ctx.userData['Ip'] as string },
});
if (db_ip) {
console.log(db_ip);
const create_session = await ctx.prisma.web_session.create({
data: {
ipAddress: {
connect: { id: db_ip[0]['id'] },
},
userAgent: ctx.userData['user_agent'] as string,
},
});
return create_session;
}
} catch (error) {
console.log("error could not add session to db");
throw error;
} finally {
ctx.prisma.$disconnect();
}
}),
1 Reply
ideceddy
ideceddyOP2y ago
I got the error to go away. It was my use of finally on the 4th to last line. Chat-GPT told me to add it against my better judgement. My guess is that I can't close the db because I don't have access to the prisma connection at this point in the code.
Want results from more Discord servers?
Add your server