mirror of
https://gh-proxy.org/https://github.com/klinsmaya/SQLBot.git
synced 2026-11-08 01:06:59 +08:00
fix: improve export empty chat excel error info
This commit is contained in:
@@ -13,7 +13,7 @@ from apps.chat.curd.chat import list_chats, get_chat_with_records, create_chat,
|
||||
delete_chat, get_chat_chart_data, get_chat_predict_data, get_chat_with_records_with_data, get_chat_record_by_id
|
||||
from apps.chat.models.chat_model import CreateChat, ChatRecord, RenameChat, ChatQuestion, ExcelData
|
||||
from apps.chat.task.llm import LLMService
|
||||
from common.core.deps import CurrentAssistant, SessionDep, CurrentUser
|
||||
from common.core.deps import CurrentAssistant, SessionDep, CurrentUser, Trans
|
||||
|
||||
router = APIRouter(tags=["Data Q&A"], prefix="/chat")
|
||||
|
||||
@@ -106,7 +106,7 @@ async def start_chat(session: SessionDep, current_user: CurrentUser):
|
||||
async def recommend_questions(session: SessionDep, current_user: CurrentUser, chat_record_id: int,
|
||||
current_assistant: CurrentAssistant):
|
||||
def _return_empty():
|
||||
yield 'data:' + orjson.dumps( {'content': '[]', 'type': 'recommended_question'}).decode() + '\n\n'
|
||||
yield 'data:' + orjson.dumps({'content': '[]', 'type': 'recommended_question'}).decode() + '\n\n'
|
||||
|
||||
try:
|
||||
record = get_chat_record_by_id(session, chat_record_id)
|
||||
@@ -201,10 +201,16 @@ async def analysis_or_predict(session: SessionDep, current_user: CurrentUser, ch
|
||||
|
||||
|
||||
@router.post("/excel/export")
|
||||
async def export_excel(excel_data: ExcelData):
|
||||
async def export_excel(excel_data: ExcelData, trans: Trans):
|
||||
def inner():
|
||||
_fields_list = []
|
||||
data = []
|
||||
if not excel_data.data:
|
||||
raise HTTPException(
|
||||
status_code=500,
|
||||
detail=trans("i18n_excel_export.data_is_empty")
|
||||
)
|
||||
|
||||
for _data in excel_data.data:
|
||||
_row = []
|
||||
for field in excel_data.axis:
|
||||
|
||||
@@ -47,5 +47,8 @@
|
||||
"datasource_cannot_be_none": "Datasource cannot be none",
|
||||
"data_training_not_exists": "Example does not exists",
|
||||
"exists_in_db": "Question exists"
|
||||
},
|
||||
"i18n_excel_export": {
|
||||
"data_is_empty": "The form data is empty, cannot export data"
|
||||
}
|
||||
}
|
||||
@@ -47,5 +47,8 @@
|
||||
"datasource_cannot_be_none": "数据源不能为空",
|
||||
"data_training_not_exists": "该示例不存在",
|
||||
"exists_in_db": "该问题已存在"
|
||||
},
|
||||
"i18n_excel_export": {
|
||||
"data_is_empty": "表单数据为空,无法导出数据"
|
||||
}
|
||||
}
|
||||
@@ -332,5 +332,9 @@ export const chatApi = {
|
||||
return request.fetchStream(`/chat/recommend_questions/${record_id}`, {}, controller)
|
||||
},
|
||||
checkLLMModel: () => request.get('/system/aimodel/default', { requestOptions: { silent: true } }),
|
||||
export2Excel: (data: any) => request.post('/chat/excel/export', data, { responseType: 'blob' }),
|
||||
export2Excel: (data: any) =>
|
||||
request.post('/chat/excel/export', data, {
|
||||
responseType: 'blob',
|
||||
requestOptions: { customError: true },
|
||||
}),
|
||||
}
|
||||
|
||||
@@ -255,6 +255,31 @@ function exportToExcel() {
|
||||
link.click()
|
||||
document.body.removeChild(link)
|
||||
})
|
||||
.catch(async (error) => {
|
||||
if (error.response) {
|
||||
try {
|
||||
let text = await error.response.data.text()
|
||||
try {
|
||||
text = JSON.parse(text)
|
||||
} finally {
|
||||
ElMessage({
|
||||
message: text,
|
||||
type: 'error',
|
||||
showClose: true,
|
||||
})
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Error processing error response:', e)
|
||||
}
|
||||
} else {
|
||||
console.error('Other error:', error)
|
||||
ElMessage({
|
||||
message: error,
|
||||
type: 'error',
|
||||
showClose: true,
|
||||
})
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user