[WIKI-704] fix: hocuspocus error handling (#7898)
This commit is contained in:
parent
794271ac17
commit
f6677f252f
3 changed files with 16 additions and 5 deletions
|
|
@ -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)
|
||||||
|
|
|
||||||
|
|
@ -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}`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue