[WIKI-704] fix: hocuspocus error handling (#7898)

This commit is contained in:
M. Palanikannan 2025-10-03 14:01:38 +05:30 committed by GitHub
parent 794271ac17
commit f6677f252f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 16 additions and 5 deletions

View file

@ -84,6 +84,7 @@ ATTRIBUTES = {
"style", "style",
"start", "start",
"type", "type",
"xmlns",
# common editor data-* attributes seen in stored HTML # common editor data-* attributes seen in stored HTML
# (wildcards like data-* are NOT supported by nh3; we add known keys # (wildcards like data-* are NOT supported by nh3; we add known keys
# here and dynamically include all data-* seen in the input below) # here and dynamically include all data-* seen in the input below)

View file

@ -11,6 +11,16 @@ import { getPageService } from "@/services/page/handler";
// type // type
import type { FetchPayloadWithContext, StorePayloadWithContext } from "@/types"; 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) => { const fetchDocument = async ({ context, documentName: pageId }: FetchPayloadWithContext) => {
try { try {
const service = getPageService(context.documentType, context); const service = getPageService(context.documentType, context);
@ -29,7 +39,7 @@ const fetchDocument = async ({ context, documentName: pageId }: FetchPayloadWith
return binaryData; return binaryData;
} catch (error) { } catch (error) {
logger.error("Error in fetching document", 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_html: contentHTML,
description: contentJSON, description: contentJSON,
}; };
return service.updateDescriptionBinary(pageId, payload); await service.updateDescriptionBinary(pageId, payload);
} catch (error) { } catch (error) {
logger.error("Error in updating document:", error); logger.error("Error in updating document:", error);
throw error; throw normalizeToError(error, `Failed to update document: ${pageId}`);
} }
}; };

View file

@ -21,7 +21,7 @@ export abstract class PageCoreService extends APIService {
}) })
.then((response) => response?.data) .then((response) => response?.data)
.catch((error) => { .catch((error) => {
throw error?.response?.data; throw error;
}); });
} }
@ -35,7 +35,7 @@ export abstract class PageCoreService extends APIService {
}) })
.then((response) => response?.data) .then((response) => response?.data)
.catch((error) => { .catch((error) => {
throw error?.response?.data; throw error;
}); });
} }