Skip to content

Commit

Permalink
fix: add error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
DeepaPrasanna committed Sep 20, 2024
1 parent caf3f87 commit db49abd
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions apps/dashboard/lib/trpc/routers/key/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,30 @@ async function upsertIdentity(
set: {
updatedAt: Date.now(),
},
})
.catch((_err) => {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message: "Failed to insert identity",
});
});

identity = await db.query.identities
.findFirst({
where: (table, { and, eq }) =>
and(eq(table.workspaceId, workspaceId), eq(table.externalId, externalId)),
})
.catch((_err) => {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message: "Failed to read identity after upsert",
});
});

identity = await db.query.identities.findFirst({
where: (table, { and, eq }) =>
and(eq(table.workspaceId, workspaceId), eq(table.externalId, externalId)),
});
if (!identity) {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message: "Failed to read identity after upsert",
code: "NOT_FOUND",
message: "No identity present!",
});
}
return identity;
Expand Down

0 comments on commit db49abd

Please sign in to comment.