Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

chore: improve logging for better error response

Marc Seitz51f3ef2e07ac
diff --git a/lib/team/helper.ts b/lib/team/helper.ts
index 7edcb33a..f0251ca9 100644
--- a/lib/team/helper.ts
+++ b/lib/team/helper.ts
@@ -62,7 +62,7 @@ export async function getTeamWithUsersAndDocument({
| (Document & { views?: View[]; versions?: DocumentVersion[]; links?: Link[] })
| undefined;
if (docId) {
- document = team?.documents.find((doc) => doc.id === docId);
+ document = team.documents.find((doc) => doc.id === docId);
if (!document) {
throw new TeamError("Document doesn't exists in the team");
}
diff --git a/pages/api/teams/[teamId]/documents/index.ts b/pages/api/teams/[teamId]/documents/index.ts
index 613d974e..e3ba1c93 100644
--- a/pages/api/teams/[teamId]/documents/index.ts
+++ b/pages/api/teams/[teamId]/documents/index.ts
@@ -62,15 +62,15 @@ export default async function handle(
const userId = (session.user as CustomUser).id;
+ // Assuming data is an object with `name` and `description` properties
+ const { name, url: fileUrl, numPages } = req.body as { name: string; url: string; numPages: number }
+
try {
await getTeamWithUsersAndDocument({
teamId,
userId,
});
- // Assuming data is an object with `name` and `description` properties
- const { name, url, numPages } = req.body;
-
// Get the file extension and save it as the type
const type = getExtension(name);
@@ -81,7 +81,7 @@ export default async function handle(
data: {
name: name,
numPages: numPages,
- file: url,
+ file: fileUrl,
type: type,
ownerId: (session.user as CustomUser).id,
teamId: teamId,
@@ -90,7 +90,7 @@ export default async function handle(
},
versions: {
create: {
- file: url,
+ file: fileUrl,
type: type,
numPages: numPages,
isPrimary: true,
@@ -135,7 +135,9 @@ export default async function handle(
return res.status(201).json(document);
} catch (error) {
- log(`Failed to create document. Error: \n\n ${error}`);
+ log(
+ `Failed to create document. \n\n teamId: ${teamId}, file: ${fileUrl} \n\n ${error}`
+ );
errorhandler(error, res);
}
} else {
diff --git a/pages/api/teams/[teamId]/documents/update.ts b/pages/api/teams/[teamId]/documents/update.ts
index 4f02912c..e5a1a918 100644
--- a/pages/api/teams/[teamId]/documents/update.ts
+++ b/pages/api/teams/[teamId]/documents/update.ts
@@ -49,7 +49,7 @@ export default async function handle(
return res.status(201).json({ message: "Document updated successfully" });
} catch (error) {
- log(`Failed to create document. Error: \n\n ${error}`);
+ log(`Failed to update document: ${documentId}. Error: \n\n ${error}`);
errorhandler(error, res);
}
} else {
diff --git a/pages/api/teams/index.ts b/pages/api/teams/index.ts
index 9be0e9cf..f6f724f0 100644
--- a/pages/api/teams/index.ts
+++ b/pages/api/teams/index.ts
@@ -43,16 +43,6 @@ export default async function handle(
// if no teams then create a default one
if (teams.length === 0) {
-
- const userDocuments = await prisma.document.findMany({
- where: { ownerId: user.id, },
- select: { id: true, },
- });
- const userDomains = await prisma.domain.findMany({
- where: { userId: user.id, },
- select: { id: true, },
- });
-
const defaultTeamName = user.name ? `${user.name}'s Team` : "Personal Team";
const defaultTeam = await prisma.team.create({
data: {
@@ -63,13 +53,6 @@ export default async function handle(
role: "ADMIN",
},
},
- plan: user.plan || "trial",
- stripeId: user.stripeId,
- subscriptionId: user.subscriptionId,
- startsAt: user.startsAt,
- endsAt: user.endsAt,
- documents: { connect: userDocuments },
- domains: { connect: userDomains },
},
select: {
id: true,
@@ -81,7 +64,7 @@ export default async function handle(
return res.status(200).json(teams);
} catch (error) {
- log(`Failed to add domain. Error: \n\n ${error}`);
+ log(`Failed to find team for user: ${user.id} \n\n ${error}`);
errorhandler(error, res);
}
} else if (req.method === "POST") {
@@ -93,13 +76,15 @@ export default async function handle(
const { team } = req.body;
+ const user = session.user as CustomUser
+
try {
const newTeam = await prisma.team.create({
data: {
name: team,
users: {
create: {
- userId: (session.user as CustomUser).id,
+ userId: user.id,
role: "ADMIN",
},
},
@@ -111,7 +96,7 @@ export default async function handle(
return res.status(201).json(newTeam);
} catch (error) {
- log(`Failed to add domain. Error: \n\n ${error}`);
+ log(`Failed to create team "${team}" for user: ${user.id}. Error: \n\n ${error}`);
errorhandler(error, res);
}
} else {