Skip to content

Commit fecfde8

Browse files
Saby-BishopsMutugiiidogi
authored
chat: smoother missing docs error handling (fixes #9292) (#9258)
Co-authored-by: mutugiii <[email protected]> Co-authored-by: dogi <[email protected]>
1 parent 1a0957d commit fecfde8

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

chatapi/src/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ wss.on('connection', (ws) => {
4848
}));
4949
}
5050
} catch (error: any) {
51-
ws.send(`${error.message}: Cannot connect to the streaming endpoint`);
51+
if (error.message === 'missing' || error.statusCode === 404 || error.error === 'not_found') {
52+
ws.send(JSON.stringify({ 'error': 'Not Found', 'message': 'Conversation not found' }));
53+
} else {
54+
ws.send(JSON.stringify({ 'error': 'Internal Server Error', 'message': error.message }));
55+
}
5256
}
5357
});
5458

@@ -80,6 +84,9 @@ app.post('/', async (req: any, res: any) => {
8084
});
8185
}
8286
} catch (error: any) {
87+
if (error.message === 'missing' || error.statusCode === 404 || error.error === 'not_found') {
88+
return res.status(404).json({ 'error': 'Not Found', 'message': 'Conversation not found' });
89+
}
8390
return res.status(500).json({ 'error': 'Internal Server Error', 'message': error.message });
8491
}
8592
});

chatapi/src/utils/db.utils.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,14 @@ import { ChatMessage } from '../models/chat.model';
88
* @returns Array of chat conversations
99
*/
1010
async function getChatDocument(id: string) {
11-
try {
12-
const res = await chatDB.get(id) as DbDoc;
13-
return {
14-
'conversations': res.conversations,
15-
'title': res.title,
16-
'createdDate': res.createdDate,
17-
'aiProvider': res.aiProvider
18-
};
19-
// Should return user, team data as well particularly for the "/conversations" endpoint
20-
} catch (error) {
21-
return {
22-
'conversations': [],
23-
'title': ''
24-
};
25-
}
11+
const res = await chatDB.get(id) as DbDoc;
12+
return {
13+
'conversations': res.conversations,
14+
'title': res.title,
15+
'createdDate': res.createdDate,
16+
'aiProvider': res.aiProvider
17+
};
18+
// Should return user, team data as well particularly for the "/conversations" endpoint
2619
}
2720

2821
export async function retrieveChatHistory(dbData: any, messages: ChatMessage[]) {

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "planet",
33
"license": "AGPL-3.0",
4-
"version": "0.20.67",
4+
"version": "0.20.68",
55
"myplanet": {
6-
"latest": "v0.36.54",
7-
"min": "v0.35.54"
6+
"latest": "v0.36.64",
7+
"min": "v0.35.64"
88
},
99
"scripts": {
1010
"ng": "ng",

0 commit comments

Comments
 (0)