Skip to content

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

fix: add invalid notion document

Marc Seitz1ebaf3a8d111
diff --git a/components/documents/add-document-modal.tsx b/components/documents/add-document-modal.tsx
index 787f58f6..13ef50ac 100644
--- a/components/documents/add-document-modal.tsx
+++ b/components/documents/add-document-modal.tsx
@@ -363,71 +363,73 @@ export function AddDocumentModal({
},
);
- if (response) {
- const document = await response.json();
+ if (!response.ok) {
+ const { error } = await response.json();
+ toast.error(error);
+ return;
+ }
- if (isDataroom && dataroomId) {
- const dataroomResponse = await addDocumentToDataroom({
- documentId: document.id,
- folderPathName: currentFolderPath?.join("/"),
- });
+ const document = await response.json();
- if (dataroomResponse?.ok) {
- const dataroomDocument =
- (await dataroomResponse.json()) as DataroomDocument & {
- dataroom: { _count: { viewerGroups: number } };
- };
+ if (isDataroom && dataroomId) {
+ const dataroomResponse = await addDocumentToDataroom({
+ documentId: document.id,
+ folderPathName: currentFolderPath?.join("/"),
+ });
- if (dataroomDocument.dataroom._count.viewerGroups > 0) {
- setShowGroupPermissions(true);
- setUploadedFiles([
- {
- documentId: document.id,
- dataroomDocumentId: dataroomDocument.id,
- fileName: document.name,
- },
- ]);
- }
+ if (dataroomResponse?.ok) {
+ const dataroomDocument =
+ (await dataroomResponse.json()) as DataroomDocument & {
+ dataroom: { _count: { viewerGroups: number } };
+ };
+
+ if (dataroomDocument.dataroom._count.viewerGroups > 0) {
+ setShowGroupPermissions(true);
+ setUploadedFiles([
+ {
+ documentId: document.id,
+ dataroomDocumentId: dataroomDocument.id,
+ fileName: document.name,
+ },
+ ]);
}
+ }
- analytics.capture("Document Added", {
- documentId: document.id,
- name: document.name,
- numPages: document.numPages,
- path: router.asPath,
- type: "notion",
+ analytics.capture("Document Added", {
+ documentId: document.id,
+ name: document.name,
+ numPages: document.numPages,
+ path: router.asPath,
+ type: "notion",
+ teamId: teamId,
+ dataroomId: dataroomId,
+ $set: {
teamId: teamId,
- dataroomId: dataroomId,
- $set: {
- teamId: teamId,
- teamPlan: plan,
- },
- });
-
- return;
- }
+ teamPlan: plan,
+ },
+ });
- if (!newVersion) {
- toast.success(
- "Notion Page processed. Redirecting to document page...",
- );
+ return;
+ }
- analytics.capture("Document Added", {
- documentId: document.id,
- name: document.name,
- fileSize: null,
- path: router.asPath,
- type: "notion",
+ if (!newVersion) {
+ toast.success("Notion Page processed. Redirecting to document page...");
+
+ analytics.capture("Document Added", {
+ documentId: document.id,
+ name: document.name,
+ fileSize: null,
+ path: router.asPath,
+ type: "notion",
+ teamId: teamId,
+ $set: {
teamId: teamId,
- $set: {
- teamId: teamId,
- teamPlan: plan,
- },
- });
+ teamPlan: plan,
+ },
+ });
- // redirect to the document page
- router.push("/documents/" + document.id);
- }
+ // redirect to the document page
+ router.push("/documents/" + document.id);
}
} catch (error) {
setUploading(false);
diff --git a/lib/documents/create-document.ts b/lib/documents/create-document.ts
index 845c604d..30cb4129 100644
--- a/lib/documents/create-document.ts
+++ b/lib/documents/create-document.ts
@@ -49,7 +49,8 @@ export const createDocument = async ({
);
if (!response.ok) {
- throw new Error(`HTTP error! status: ${response.status}`);
+ const error = await response.json();
+ throw new Error(error);
}
return response;