Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
webapp-conversation
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tech
webapp-conversation
Commits
87a063c3
Commit
87a063c3
authored
May 15, 2023
by
金伟强
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: res is not json
parent
b35aa0b1
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
20 deletions
+26
-20
base.ts
service/base.ts
+26
-20
No files found.
service/base.ts
View file @
87a063c3
...
...
@@ -62,7 +62,8 @@ const handleStream = (response: any, onData: IOnData, onCompleted?: IOnCompleted
const
lines
=
buffer
.
split
(
'
\
n'
)
try
{
lines
.
forEach
((
message
)
=>
{
if
(
!
message
)
return
if
(
!
message
)
return
bufferObj
=
JSON
.
parse
(
message
)
// remove data: and parse as json
onData
(
unicodeToChar
(
bufferObj
.
answer
),
isFirstMessage
,
{
conversationId
:
bufferObj
.
conversation_id
,
...
...
@@ -71,11 +72,12 @@ const handleStream = (response: any, onData: IOnData, onCompleted?: IOnCompleted
isFirstMessage
=
false
})
buffer
=
lines
[
lines
.
length
-
1
]
}
catch
(
e
)
{
}
catch
(
e
)
{
onData
(
''
,
false
,
{
conversationId
:
undefined
,
messageId
:
''
,
errorMessage
:
e
+
''
errorMessage
:
`
${
e
}
`
,
})
return
}
...
...
@@ -89,7 +91,7 @@ const handleStream = (response: any, onData: IOnData, onCompleted?: IOnCompleted
const
baseFetch
=
(
url
:
string
,
fetchOptions
:
any
,
{
needAllResponseContent
}:
IOtherOptions
)
=>
{
const
options
=
Object
.
assign
({},
baseOptions
,
fetchOptions
)
le
t
urlPrefix
=
API_PREFIX
cons
t
urlPrefix
=
API_PREFIX
let
urlWithPrefix
=
`
${
urlPrefix
}${
url
.
startsWith
(
'/'
)
?
url
:
`/
${
url
}
`
}
`
...
...
@@ -125,12 +127,12 @@ const baseFetch = (url: string, fetchOptions: any, { needAllResponseContent }: I
const
resClone
=
res
.
clone
()
// Error handler
if
(
!
/^
(
2|3
)\d{2}
$/
.
test
(
res
.
status
))
{
try
{
const
bodyJson
=
res
.
json
()
switch
(
res
.
status
)
{
case
401
:
{
Toast
.
notify
({
type
:
'error'
,
message
:
'Invalid token'
})
return
}
default
:
// eslint-disable-next-line no-new
...
...
@@ -140,12 +142,17 @@ const baseFetch = (url: string, fetchOptions: any, { needAllResponseContent }: I
})
})
}
}
catch
(
e
)
{
Toast
.
notify
({
type
:
'error'
,
message
:
`
${
e
}
`
})
}
return
Promise
.
reject
(
resClone
)
}
// handle delete api. Delete api not return content.
if
(
res
.
status
===
204
)
{
resolve
({
result
:
"success"
})
resolve
({
result
:
'success'
})
return
}
...
...
@@ -162,8 +169,7 @@ const baseFetch = (url: string, fetchOptions: any, { needAllResponseContent }: I
])
}
export
const
ssePost
=
(
url
:
string
,
fetchOptions
:
any
,
{
onData
,
onCompleted
,
onError
}:
IOtherOptions
)
=>
{
export
const
ssePost
=
(
url
:
string
,
fetchOptions
:
any
,
{
onData
,
onCompleted
,
onError
}:
IOtherOptions
)
=>
{
const
options
=
Object
.
assign
({},
baseOptions
,
{
method
:
'POST'
,
},
fetchOptions
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment