mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-13 14:08:51 +01:00
chore: improve meili error handling
This commit is contained in:
parent
68979015c1
commit
655e7ce6d6
9 changed files with 182 additions and 64 deletions
|
|
@ -26,8 +26,8 @@ BING_TOKEN=
|
|||
# this is taken care of you if you use the docker-compose file.
|
||||
# SEARCH=TRUE
|
||||
SEARCH=
|
||||
MEILI_HOST='http://localhost:7700'
|
||||
MEILI_HTTP_ADDR='http://localhost:7700'
|
||||
MEILI_HOST='http://0.0.0.0:7700'
|
||||
MEILI_HTTP_ADDR='0.0.0.0:7700'
|
||||
# needs a secure key, feel free to generate your own.
|
||||
MEILI_MASTER_KEY=WjRvKvpelIYHa4dlcDGsdT9c0CKRbY-4VcuCQ1iZPcc
|
||||
|
||||
|
|
|
|||
|
|
@ -43,8 +43,21 @@ async function indexSync(req, res, next) {
|
|||
await Conversation.syncWithMeili();
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
// res.status(500).json({ error: 'Server error' });
|
||||
// console.log('in index sync');
|
||||
if (err.message.includes('not found')) {
|
||||
console.log('Creating indices...');
|
||||
setTimeout(async () => {
|
||||
try {
|
||||
await Message.syncWithMeili();
|
||||
await Conversation.syncWithMeili();
|
||||
} catch (err) {
|
||||
console.error('Trouble creating indices, try restarting the server.');
|
||||
}
|
||||
}, 750);
|
||||
} else {
|
||||
console.error(err);
|
||||
// res.status(500).json({ error: 'Server error' });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,11 +3,13 @@ const handleDuplicateKeyError = (err, res) => {
|
|||
const field = Object.keys(err.keyValue);
|
||||
const code = 409;
|
||||
const error = `An document with that ${field} already exists.`;
|
||||
console.log('congrats you hit the duped keys error');
|
||||
res.status(code).send({ messages: error, fields: field });
|
||||
};
|
||||
|
||||
//handle validation errors
|
||||
const handleValidationError = (err, res) => {
|
||||
console.log('congrats you hit the validation middleware');
|
||||
let errors = Object.values(err.errors).map(el => el.message);
|
||||
let fields = Object.values(err.errors).map(el => el.path);
|
||||
let code = 400;
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ const projectPath = path.join(__dirname, '..', '..', 'client');
|
|||
|
||||
let messageCount = 0;
|
||||
process.on('uncaughtException', (err) => {
|
||||
// console.error('There was an uncaught error:', err.message);
|
||||
console.error('There was an uncaught error:', err.message);
|
||||
if (err.message.includes('fetch failed')) {
|
||||
if (messageCount === 0) console.error('Meilisearch error, search will be disabled');
|
||||
messageCount++;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ const { MeiliSearch } = require('meilisearch');
|
|||
const { Message } = require('../../models/Message');
|
||||
const { Conversation, getConvosQueried } = require('../../models/Conversation');
|
||||
const { reduceHits } = require('../../lib/utils/reduceHits');
|
||||
const { replaceSup, cleanUpPrimaryKeyValue } = require('../../lib/utils/misc');
|
||||
const { cleanUpPrimaryKeyValue } = require('../../lib/utils/misc');
|
||||
const cache = new Map();
|
||||
|
||||
router.get('/sync', async function (req, res) {
|
||||
|
|
@ -46,7 +46,7 @@ router.get('/', async function (req, res) {
|
|||
return {
|
||||
...rest,
|
||||
searchResult: true,
|
||||
text: replaceSup(_formatted.text)
|
||||
text: _formatted.text
|
||||
};
|
||||
});
|
||||
const titles = (await Conversation.meiliSearch(q)).hits;
|
||||
|
|
@ -55,8 +55,6 @@ router.get('/', async function (req, res) {
|
|||
const result = await getConvosQueried(user, sortedHits, pageNumber);
|
||||
cache.set(key, result.cache);
|
||||
delete result.cache;
|
||||
// result.messages = messages.filter(message => { });
|
||||
// !result.filter.has(message.conversationId)
|
||||
|
||||
const activeMessages = [];
|
||||
for (let i = 0; i < messages.length; i++) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue