[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

@ -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}`);
}
};

View file

@ -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;
});
}