pref: reduce code

This commit is contained in:
ChenZhaoYu
2023-02-10 09:19:37 +08:00
parent e8cb651db3
commit ac6e860a67
21 changed files with 147 additions and 1126 deletions

View File

@@ -4,18 +4,16 @@ async function fetchChatAPI(message: string) {
const url = `${import.meta.env.VITE_GLOB_API_URL}/chat`
if (!message || message.trim() === '')
return Promise.reject(new Error('Message is empty'))
return
try {
const { status, data } = await axios.post(
url,
{ message },
)
const { status, data } = await axios.post(url, { message })
if (status === 200) {
if (data.text)
return Promise.resolve(data)
else if (data.statusText)
if (data.statusText)
return Promise.reject(new Error(data.statusText))
}