mirror of
https://github.com/makeplane/plane.git
synced 2026-01-30 18:29:30 -06:00
[WIKI-704] fix: hocuspocus error handling (#7898)
This commit is contained in:
@@ -84,6 +84,7 @@ ATTRIBUTES = {
|
||||
"style",
|
||||
"start",
|
||||
"type",
|
||||
"xmlns",
|
||||
# common editor data-* attributes seen in stored HTML
|
||||
# (wildcards like data-* are NOT supported by nh3; we add known keys
|
||||
# here and dynamically include all data-* seen in the input below)
|
||||
|
||||
@@ -11,6 +11,16 @@ import { getPageService } from "@/services/page/handler";
|
||||
// type
|
||||
import type { FetchPayloadWithContext, StorePayloadWithContext } from "@/types";
|
||||
|
||||
const normalizeToError = (error: unknown, fallbackMessage: string) => {
|
||||
if (error instanceof Error) {
|
||||
return error;
|
||||
}
|
||||
|
||||
const message = typeof error === "string" && error.trim().length > 0 ? error : fallbackMessage;
|
||||
|
||||
return new Error(message);
|
||||
};
|
||||
|
||||
const fetchDocument = async ({ context, documentName: pageId }: FetchPayloadWithContext) => {
|
||||
try {
|
||||
const service = getPageService(context.documentType, context);
|
||||
@@ -29,7 +39,7 @@ const fetchDocument = async ({ context, documentName: pageId }: FetchPayloadWith
|
||||
return binaryData;
|
||||
} catch (error) {
|
||||
logger.error("Error in fetching document", error);
|
||||
throw error;
|
||||
throw normalizeToError(error, `Failed to fetch document: ${pageId}`);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -45,10 +55,10 @@ const storeDocument = async ({ context, state: pageBinaryData, documentName: pag
|
||||
description_html: contentHTML,
|
||||
description: contentJSON,
|
||||
};
|
||||
return service.updateDescriptionBinary(pageId, payload);
|
||||
await service.updateDescriptionBinary(pageId, payload);
|
||||
} catch (error) {
|
||||
logger.error("Error in updating document:", error);
|
||||
throw error;
|
||||
throw normalizeToError(error, `Failed to update document: ${pageId}`);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ export abstract class PageCoreService extends APIService {
|
||||
})
|
||||
.then((response) => response?.data)
|
||||
.catch((error) => {
|
||||
throw error?.response?.data;
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ export abstract class PageCoreService extends APIService {
|
||||
})
|
||||
.then((response) => response?.data)
|
||||
.catch((error) => {
|
||||
throw error?.response?.data;
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user