pref: reduce code
This commit is contained in:
@@ -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))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user