fix(chats): surface the error message instead of [object Object] (#28260)
This commit is contained in:
+40
-32
@@ -1,6 +1,14 @@
|
||||
import { WEBUI_API_BASE_URL } from '$lib/constants';
|
||||
import { getTimeRange } from '$lib/utils';
|
||||
|
||||
const getErrorDetail = (err: any) => {
|
||||
if (Array.isArray(err?.detail)) {
|
||||
return err.detail.map((e: { msg?: string }) => e.msg || JSON.stringify(e)).join(', ');
|
||||
}
|
||||
|
||||
return err?.detail ?? err;
|
||||
};
|
||||
|
||||
export const getChatConfig = async (token: string) => {
|
||||
let error = null;
|
||||
|
||||
@@ -17,7 +25,7 @@ export const getChatConfig = async (token: string) => {
|
||||
return res.json();
|
||||
})
|
||||
.catch((err) => {
|
||||
error = err;
|
||||
error = getErrorDetail(err);
|
||||
console.error(err);
|
||||
return null;
|
||||
});
|
||||
@@ -46,7 +54,7 @@ export const updateChatConfig = async (token: string, config: object) => {
|
||||
return res.json();
|
||||
})
|
||||
.catch((err) => {
|
||||
error = err;
|
||||
error = getErrorDetail(err);
|
||||
console.error(err);
|
||||
return null;
|
||||
});
|
||||
@@ -84,7 +92,7 @@ export const createNewChat = async (
|
||||
return res.json();
|
||||
})
|
||||
.catch((err) => {
|
||||
error = err;
|
||||
error = getErrorDetail(err);
|
||||
console.error(err);
|
||||
return null;
|
||||
});
|
||||
@@ -179,7 +187,7 @@ export const importChats = async (token: string, chats: object[]) => {
|
||||
return res.json();
|
||||
})
|
||||
.catch((err) => {
|
||||
error = err;
|
||||
error = getErrorDetail(err);
|
||||
console.error(err);
|
||||
return null;
|
||||
});
|
||||
@@ -228,7 +236,7 @@ export const getChatList = async (
|
||||
return json;
|
||||
})
|
||||
.catch((err) => {
|
||||
error = err;
|
||||
error = getErrorDetail(err);
|
||||
console.error(err);
|
||||
return null;
|
||||
});
|
||||
@@ -286,7 +294,7 @@ export const getChatListByUserId = async (
|
||||
return json;
|
||||
})
|
||||
.catch((err) => {
|
||||
error = err;
|
||||
error = getErrorDetail(err);
|
||||
console.error(err);
|
||||
return null;
|
||||
});
|
||||
@@ -335,7 +343,7 @@ export const getArchivedChatList = async (
|
||||
return json;
|
||||
})
|
||||
.catch((err) => {
|
||||
error = err;
|
||||
error = getErrorDetail(err);
|
||||
console.error(err);
|
||||
return null;
|
||||
});
|
||||
@@ -366,7 +374,7 @@ export const getArchivedChatCount = async (token: string = '') => {
|
||||
return res.json();
|
||||
})
|
||||
.catch((err) => {
|
||||
error = err;
|
||||
error = getErrorDetail(err);
|
||||
console.error(err);
|
||||
return null;
|
||||
});
|
||||
@@ -408,7 +416,7 @@ export const getSharedChatList = async (token: string = '', page: number = 1, fi
|
||||
return json;
|
||||
})
|
||||
.catch((err) => {
|
||||
error = err;
|
||||
error = getErrorDetail(err);
|
||||
console.error(err);
|
||||
return null;
|
||||
});
|
||||
@@ -496,7 +504,7 @@ export const getChatListBySearchText = async (token: string, text: string, page:
|
||||
return json;
|
||||
})
|
||||
.catch((err) => {
|
||||
error = err;
|
||||
error = getErrorDetail(err);
|
||||
console.error(err);
|
||||
return null;
|
||||
});
|
||||
@@ -530,7 +538,7 @@ export const getChatsByFolderId = async (token: string, folderId: string) => {
|
||||
return json;
|
||||
})
|
||||
.catch((err) => {
|
||||
error = err;
|
||||
error = getErrorDetail(err);
|
||||
console.error(err);
|
||||
return null;
|
||||
});
|
||||
@@ -569,7 +577,7 @@ export const getChatListByFolderId = async (token: string, folderId: string, pag
|
||||
return json;
|
||||
})
|
||||
.catch((err) => {
|
||||
error = err;
|
||||
error = getErrorDetail(err);
|
||||
console.error(err);
|
||||
return null;
|
||||
});
|
||||
@@ -600,7 +608,7 @@ export const getAllArchivedChats = async (token: string) => {
|
||||
return json;
|
||||
})
|
||||
.catch((err) => {
|
||||
error = err;
|
||||
error = getErrorDetail(err);
|
||||
console.error(err);
|
||||
return null;
|
||||
});
|
||||
@@ -631,7 +639,7 @@ export const getAllUserChats = async (token: string) => {
|
||||
return json;
|
||||
})
|
||||
.catch((err) => {
|
||||
error = err;
|
||||
error = getErrorDetail(err);
|
||||
console.error(err);
|
||||
return null;
|
||||
});
|
||||
@@ -662,7 +670,7 @@ export const getAllTags = async (token: string) => {
|
||||
return json;
|
||||
})
|
||||
.catch((err) => {
|
||||
error = err;
|
||||
error = getErrorDetail(err);
|
||||
console.error(err);
|
||||
return null;
|
||||
});
|
||||
@@ -693,7 +701,7 @@ export const getPinnedChatList = async (token: string = '') => {
|
||||
return json;
|
||||
})
|
||||
.catch((err) => {
|
||||
error = err;
|
||||
error = getErrorDetail(err);
|
||||
console.error(err);
|
||||
return null;
|
||||
});
|
||||
@@ -730,7 +738,7 @@ export const getChatListByTagName = async (token: string = '', tagName: string)
|
||||
return json;
|
||||
})
|
||||
.catch((err) => {
|
||||
error = err;
|
||||
error = getErrorDetail(err);
|
||||
console.error(err);
|
||||
return null;
|
||||
});
|
||||
@@ -796,7 +804,7 @@ export const getChatByShareId = async (token: string, share_id: string) => {
|
||||
return json;
|
||||
})
|
||||
.catch((err) => {
|
||||
error = err;
|
||||
error = getErrorDetail(err);
|
||||
|
||||
console.error(err);
|
||||
return null;
|
||||
@@ -1080,7 +1088,7 @@ export const shareChatById = async (token: string, id: string) => {
|
||||
return json;
|
||||
})
|
||||
.catch((err) => {
|
||||
error = err;
|
||||
error = getErrorDetail(err);
|
||||
|
||||
console.error(err);
|
||||
return null;
|
||||
@@ -1115,7 +1123,7 @@ export const updateChatFolderIdById = async (token: string, id: string, folderId
|
||||
return json;
|
||||
})
|
||||
.catch((err) => {
|
||||
error = err;
|
||||
error = getErrorDetail(err);
|
||||
|
||||
console.error(err);
|
||||
return null;
|
||||
@@ -1147,7 +1155,7 @@ export const archiveChatById = async (token: string, id: string) => {
|
||||
return json;
|
||||
})
|
||||
.catch((err) => {
|
||||
error = err;
|
||||
error = getErrorDetail(err);
|
||||
|
||||
console.error(err);
|
||||
return null;
|
||||
@@ -1179,7 +1187,7 @@ export const deleteSharedChatById = async (token: string, id: string) => {
|
||||
return json;
|
||||
})
|
||||
.catch((err) => {
|
||||
error = err;
|
||||
error = getErrorDetail(err);
|
||||
|
||||
console.error(err);
|
||||
return null;
|
||||
@@ -1214,7 +1222,7 @@ export const updateChatAccessGrants = async (token: string, id: string, accessGr
|
||||
return json;
|
||||
})
|
||||
.catch((err) => {
|
||||
error = err;
|
||||
error = getErrorDetail(err);
|
||||
|
||||
console.error(err);
|
||||
return null;
|
||||
@@ -1246,7 +1254,7 @@ export const getChatAccessGrants = async (token: string, id: string) => {
|
||||
return json;
|
||||
})
|
||||
.catch((err) => {
|
||||
error = err;
|
||||
error = getErrorDetail(err);
|
||||
|
||||
console.error(err);
|
||||
return null;
|
||||
@@ -1287,7 +1295,7 @@ export const updateChatById = async (
|
||||
return json;
|
||||
})
|
||||
.catch((err) => {
|
||||
error = err;
|
||||
error = getErrorDetail(err);
|
||||
|
||||
console.error(err);
|
||||
return null;
|
||||
@@ -1320,7 +1328,7 @@ export const compactChatById = async (token: string, id: string, model?: string
|
||||
return json;
|
||||
})
|
||||
.catch((err) => {
|
||||
error = err;
|
||||
error = getErrorDetail(err);
|
||||
|
||||
console.error(err);
|
||||
return null;
|
||||
@@ -1349,7 +1357,7 @@ export const deleteChatMessageById = async (token: string, id: string, messageId
|
||||
return res.json();
|
||||
})
|
||||
.catch((err) => {
|
||||
error = err;
|
||||
error = getErrorDetail(err);
|
||||
console.error(err);
|
||||
return null;
|
||||
});
|
||||
@@ -1412,7 +1420,7 @@ export const getTagsById = async (token: string, id: string) => {
|
||||
return json;
|
||||
})
|
||||
.catch((err) => {
|
||||
error = err;
|
||||
error = getErrorDetail(err);
|
||||
|
||||
console.error(err);
|
||||
return null;
|
||||
@@ -1481,7 +1489,7 @@ export const deleteTagById = async (token: string, id: string, tagName: string)
|
||||
return json;
|
||||
})
|
||||
.catch((err) => {
|
||||
error = err;
|
||||
error = getErrorDetail(err);
|
||||
|
||||
console.error(err);
|
||||
return null;
|
||||
@@ -1585,7 +1593,7 @@ export const exportChatStats = async (token: string, page: number = 1, params: o
|
||||
return json;
|
||||
})
|
||||
.catch((err) => {
|
||||
error = err;
|
||||
error = getErrorDetail(err);
|
||||
console.error(err);
|
||||
return null;
|
||||
});
|
||||
@@ -1616,7 +1624,7 @@ export const exportSingleChatStats = async (token: string, chatId: string) => {
|
||||
return json;
|
||||
})
|
||||
.catch((err) => {
|
||||
error = err;
|
||||
error = getErrorDetail(err);
|
||||
console.error(err);
|
||||
return null;
|
||||
});
|
||||
@@ -1647,7 +1655,7 @@ export const downloadChatStats = async (
|
||||
}
|
||||
}).catch((err) => {
|
||||
console.error(err);
|
||||
error = err;
|
||||
error = getErrorDetail(err);
|
||||
return null;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user