Skip to content

Commit a0ee8e2

Browse files
authored
handle 204 again for AI Search (#55048)
1 parent db995fa commit a0ee8e2

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/search/lib/ai-search-proxy.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,14 @@ export const aiSearchProxy = async (req: Request, res: Response) => {
8080

8181
// Handle the upstream response before piping
8282
stream.on('response', (upstreamResponse) => {
83-
if (upstreamResponse.statusCode !== 200) {
83+
// When cse-copilot returns a 204, it means the backend received the request
84+
// but was unable to answer the question. So we return a 400 to the client to be handled.
85+
if (upstreamResponse.statusCode === 204) {
86+
statsd.increment('ai-search.unable_to_answer_query', 1, diagnosticTags)
87+
return res
88+
.status(400)
89+
.json({ errors: [{ message: 'Sorry I am unable to answer this question.' }] })
90+
} else if (upstreamResponse.statusCode !== 200) {
8491
const errorMessage = `Upstream server responded with status code ${upstreamResponse.statusCode}`
8592
console.error(errorMessage)
8693
statsd.increment('ai-search.stream_response_error', 1, diagnosticTags)

0 commit comments

Comments
 (0)