Unified API response json schema (#3170)
### What problem does this PR solve? Unified API response json schema ### Type of change - [x] Refactoring
This commit is contained in:
@@ -30,7 +30,7 @@ const ChunkCreatingModal: React.FC<IModalProps<any> & kFProps> = ({
|
||||
const { t } = useTranslation();
|
||||
|
||||
useEffect(() => {
|
||||
if (data?.retcode === 0) {
|
||||
if (data?.code === 0) {
|
||||
const { content_with_weight, important_kwd = [] } = data.data;
|
||||
form.setFieldsValue({ content: content_with_weight });
|
||||
setKeywords(important_kwd);
|
||||
|
||||
@@ -96,14 +96,14 @@ export const useUpdateChunk = () => {
|
||||
|
||||
const onChunkUpdatingOk = useCallback(
|
||||
async ({ content, keywords }: { content: string; keywords: string }) => {
|
||||
const retcode = await createChunk({
|
||||
const code = await createChunk({
|
||||
content_with_weight: content,
|
||||
doc_id: documentId,
|
||||
chunk_id: chunkId,
|
||||
important_kwd: keywords, // keywords
|
||||
});
|
||||
|
||||
if (retcode === 0) {
|
||||
if (code === 0) {
|
||||
hideChunkUpdatingModal();
|
||||
}
|
||||
},
|
||||
|
||||
@@ -148,20 +148,20 @@ export const useHandleUploadDocument = () => {
|
||||
async (fileList: UploadFile[]): Promise<number | undefined> => {
|
||||
if (fileList.length > 0) {
|
||||
const ret: any = await uploadDocument(fileList);
|
||||
if (typeof ret?.retmsg !== 'string') {
|
||||
if (typeof ret?.message !== 'string') {
|
||||
return;
|
||||
}
|
||||
const count = getUnSupportedFilesCount(ret?.retmsg);
|
||||
const count = getUnSupportedFilesCount(ret?.message);
|
||||
/// 500 error code indicates that some file types are not supported
|
||||
let retcode = ret?.retcode;
|
||||
let code = ret?.code;
|
||||
if (
|
||||
ret?.retcode === 0 ||
|
||||
(ret?.retcode === 500 && count !== fileList.length) // Some files were not uploaded successfully, but some were uploaded successfully.
|
||||
ret?.code === 0 ||
|
||||
(ret?.code === 500 && count !== fileList.length) // Some files were not uploaded successfully, but some were uploaded successfully.
|
||||
) {
|
||||
retcode = 0;
|
||||
code = 0;
|
||||
hideDocumentUploadModal();
|
||||
}
|
||||
return retcode;
|
||||
return code;
|
||||
}
|
||||
},
|
||||
[uploadDocument, hideDocumentUploadModal],
|
||||
|
||||
@@ -176,7 +176,7 @@ export const useEditDialog = () => {
|
||||
async (dialogId?: string) => {
|
||||
if (dialogId) {
|
||||
const ret = await fetchDialog(dialogId);
|
||||
if (ret.retcode === 0) {
|
||||
if (ret.code === 0) {
|
||||
setDialog(ret.data);
|
||||
}
|
||||
}
|
||||
@@ -393,7 +393,7 @@ export const useSendNextMessage = (controller: AbortController) => {
|
||||
controller,
|
||||
);
|
||||
|
||||
if (res && (res?.response.status !== 200 || res?.data?.retcode !== 0)) {
|
||||
if (res && (res?.response.status !== 200 || res?.data?.code !== 0)) {
|
||||
// cancel loading
|
||||
setValue(message.content);
|
||||
console.info('removeLatestMessage111');
|
||||
@@ -421,7 +421,7 @@ export const useSendNextMessage = (controller: AbortController) => {
|
||||
true,
|
||||
conversationId,
|
||||
);
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
setConversationIsNew('');
|
||||
const id = data.data.id;
|
||||
// currentConversationIdRef.current = id;
|
||||
@@ -541,7 +541,7 @@ export const useRenameConversation = () => {
|
||||
is_new: false,
|
||||
});
|
||||
|
||||
if (ret.retcode === 0) {
|
||||
if (ret.code === 0) {
|
||||
hideConversationRenameModal();
|
||||
}
|
||||
},
|
||||
@@ -551,7 +551,7 @@ export const useRenameConversation = () => {
|
||||
const handleShowConversationRenameModal = useCallback(
|
||||
async (conversationId: string) => {
|
||||
const ret = await fetchConversation(conversationId);
|
||||
if (ret.retcode === 0) {
|
||||
if (ret.code === 0) {
|
||||
setConversation(ret.data);
|
||||
}
|
||||
showConversationRenameModal();
|
||||
|
||||
@@ -96,7 +96,7 @@ export const useSendSharedMessage = (conversationId: string) => {
|
||||
messages: [...(derivedMessages ?? []), message],
|
||||
});
|
||||
|
||||
if (res && (res?.response.status !== 200 || res?.data?.retcode !== 0)) {
|
||||
if (res && (res?.response.status !== 200 || res?.data?.code !== 0)) {
|
||||
// cancel loading
|
||||
setValue(message.content);
|
||||
removeLatestMessage();
|
||||
@@ -111,7 +111,7 @@ export const useSendSharedMessage = (conversationId: string) => {
|
||||
sendMessage(message);
|
||||
} else {
|
||||
const data = await setConversation('user id');
|
||||
if (data.retcode === 0) {
|
||||
if (data.code === 0) {
|
||||
const id = data.data.id;
|
||||
sendMessage(message, id);
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ export const useCatchError = (api: string) => {
|
||||
const fetchDocument = useCallback(async () => {
|
||||
const ret = await axios.get(api);
|
||||
const { data } = ret;
|
||||
if (!(data instanceof ArrayBuffer) && data.retcode !== 0) {
|
||||
setError(data.retmsg);
|
||||
if (!(data instanceof ArrayBuffer) && data.code !== 0) {
|
||||
setError(data.message);
|
||||
}
|
||||
return ret;
|
||||
}, [api]);
|
||||
|
||||
@@ -141,8 +141,8 @@ export const useHandleDeleteFile = (
|
||||
const handleRemoveFile = () => {
|
||||
showDeleteConfirm({
|
||||
onOk: async () => {
|
||||
const retcode = await removeDocument({ fileIds, parentId });
|
||||
if (retcode === 0) {
|
||||
const code = await removeDocument({ fileIds, parentId });
|
||||
if (code === 0) {
|
||||
setSelectedRowKeys([]);
|
||||
}
|
||||
return;
|
||||
|
||||
@@ -22,7 +22,7 @@ const AsyncTreeSelect = ({ value, onChange }: IProps) => {
|
||||
const onLoadData: TreeSelectProps['loadData'] = useCallback(
|
||||
async ({ id }) => {
|
||||
const ret = await fetchList(id);
|
||||
if (ret.retcode === 0) {
|
||||
if (ret.code === 0) {
|
||||
setTreeData((tree) => {
|
||||
return tree.concat(
|
||||
ret.data.files
|
||||
|
||||
@@ -151,7 +151,7 @@ export const useSendMessage = (
|
||||
const res = await send(params);
|
||||
|
||||
if (receiveMessageError(res)) {
|
||||
antMessage.error(res?.data?.retmsg);
|
||||
antMessage.error(res?.data?.message);
|
||||
|
||||
// cancel loading
|
||||
setValue(message.content);
|
||||
@@ -227,7 +227,7 @@ export const useSendNextMessage = () => {
|
||||
const res = await send(params);
|
||||
|
||||
if (receiveMessageError(res)) {
|
||||
antMessage.error(res?.data?.retmsg);
|
||||
antMessage.error(res?.data?.message);
|
||||
|
||||
// cancel loading
|
||||
setValue(message.content);
|
||||
|
||||
@@ -497,15 +497,15 @@ export const useSaveGraphBeforeOpeningDebugDrawer = (show: () => void) => {
|
||||
const { send } = useSendMessageWithSse(api.runCanvas);
|
||||
const handleRun = useCallback(async () => {
|
||||
const saveRet = await saveGraph();
|
||||
if (saveRet?.retcode === 0) {
|
||||
if (saveRet?.code === 0) {
|
||||
// Call the reset api before opening the run drawer each time
|
||||
const resetRet = await resetFlow();
|
||||
// After resetting, all previous messages will be cleared.
|
||||
if (resetRet?.retcode === 0) {
|
||||
if (resetRet?.code === 0) {
|
||||
// fetch prologue
|
||||
const sendRet = await send({ id });
|
||||
if (receiveMessageError(sendRet)) {
|
||||
message.error(sendRet?.data?.retmsg);
|
||||
message.error(sendRet?.data?.message);
|
||||
} else {
|
||||
refetch();
|
||||
show();
|
||||
|
||||
@@ -53,7 +53,7 @@ export const useSaveFlow = () => {
|
||||
// },
|
||||
});
|
||||
|
||||
if (ret?.retcode === 0) {
|
||||
if (ret?.code === 0) {
|
||||
hideFlowSettingModal();
|
||||
navigate(`/flow/${ret.data.id}`);
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ export const buildDslComponentsByGraph = (
|
||||
};
|
||||
|
||||
export const receiveMessageError = (res: any) =>
|
||||
res && (res?.response.status !== 200 || res?.data?.retcode !== 0);
|
||||
res && (res?.response.status !== 200 || res?.data?.code !== 0);
|
||||
|
||||
// Replace the id in the object with text
|
||||
export const replaceIdWithText = (
|
||||
|
||||
@@ -27,7 +27,7 @@ export const useSaveKnowledge = () => {
|
||||
name,
|
||||
});
|
||||
|
||||
if (ret?.retcode === 0) {
|
||||
if (ret?.code === 0) {
|
||||
hideModal();
|
||||
navigate(
|
||||
`/knowledge/${KnowledgeRouteKey.Configuration}?id=${ret.data.kb_id}`,
|
||||
|
||||
@@ -33,20 +33,20 @@ const Login = () => {
|
||||
const rsaPassWord = rsaPsw(params.password) as string;
|
||||
|
||||
if (title === 'login') {
|
||||
const retcode = await login({
|
||||
const code = await login({
|
||||
email: params.email,
|
||||
password: rsaPassWord,
|
||||
});
|
||||
if (retcode === 0) {
|
||||
if (code === 0) {
|
||||
navigate('/knowledge');
|
||||
}
|
||||
} else {
|
||||
const retcode = await register({
|
||||
const code = await register({
|
||||
nickname: params.nickname,
|
||||
email: params.email,
|
||||
password: rsaPassWord,
|
||||
});
|
||||
if (retcode === 0) {
|
||||
if (code === 0) {
|
||||
setTitle('login');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@ export const useAddUser = () => {
|
||||
|
||||
const handleAddUserOk = useCallback(
|
||||
async (email: string) => {
|
||||
const retcode = await addTenantUser(email);
|
||||
if (retcode === 0) {
|
||||
const code = await addTenantUser(email);
|
||||
if (code === 0) {
|
||||
hideAddingTenantModal();
|
||||
}
|
||||
},
|
||||
@@ -40,8 +40,8 @@ export const useHandleDeleteUser = () => {
|
||||
const handleDeleteTenantUser = (userId: string) => () => {
|
||||
showDeleteConfirm({
|
||||
onOk: async () => {
|
||||
const retcode = await deleteTenantUser({ userId });
|
||||
if (retcode === 0) {
|
||||
const code = await deleteTenantUser({ userId });
|
||||
if (code === 0) {
|
||||
}
|
||||
return;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user