fix: interview create returns HTTP 201, frontend only accepted 200
NestJS POST 默认返回 201 Created,前端 startInterview() 和 sendAnswer() 只判断 statusCode === 200 导致成功创建也落入 else 分支显示创建面试失败。改为 >= 200 && < 300。
This commit is contained in:
@@ -224,7 +224,7 @@ const startInterview = async () => {
|
|||||||
header: { 'Authorization': `Bearer ${token()}`, 'Content-Type': 'application/json' },
|
header: { 'Authorization': `Bearer ${token()}`, 'Content-Type': 'application/json' },
|
||||||
data: { position: position.value },
|
data: { position: position.value },
|
||||||
})
|
})
|
||||||
if (res.statusCode === 200 && res.data) {
|
if (res.statusCode >= 200 && res.statusCode < 300 && res.data) {
|
||||||
interviewId.value = res.data.id
|
interviewId.value = res.data.id
|
||||||
messages.value = res.data.messages || messages.value
|
messages.value = res.data.messages || messages.value
|
||||||
answeredCount.value = res.data.questionCount || 0
|
answeredCount.value = res.data.questionCount || 0
|
||||||
@@ -274,7 +274,7 @@ const sendAnswer = async () => {
|
|||||||
header: { 'Authorization': `Bearer ${token()}`, 'Content-Type': 'application/json' },
|
header: { 'Authorization': `Bearer ${token()}`, 'Content-Type': 'application/json' },
|
||||||
data: avatarMode.value ? { answer, avatar: true } : { answer },
|
data: avatarMode.value ? { answer, avatar: true } : { answer },
|
||||||
})
|
})
|
||||||
if (res.statusCode === 200 && res.data?.messages) {
|
if (res.statusCode >= 200 && res.statusCode < 300 && res.data?.messages) {
|
||||||
const aiMsg = res.data.messages.find(m => m.role === 'ai')
|
const aiMsg = res.data.messages.find(m => m.role === 'ai')
|
||||||
// Only push AI messages from response to avoid duplicating the user message already added above
|
// Only push AI messages from response to avoid duplicating the user message already added above
|
||||||
const newAiMessages = res.data.messages.filter(m => m.role === 'ai')
|
const newAiMessages = res.data.messages.filter(m => m.role === 'ai')
|
||||||
|
|||||||
Reference in New Issue
Block a user