mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2024-11-19 12:40:09 +01:00
Exception handler on embed chat middleware
This commit is contained in:
parent
47a5c7126c
commit
548da9ade3
@ -41,6 +41,7 @@ async function validEmbedConfigId(request, response, next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function canRespond(request, response, next) {
|
async function canRespond(request, response, next) {
|
||||||
|
try {
|
||||||
const embed = response.locals.embedConfig;
|
const embed = response.locals.embedConfig;
|
||||||
if (!embed) {
|
if (!embed) {
|
||||||
response.sendStatus(404).end();
|
response.sendStatus(404).end();
|
||||||
@ -92,7 +93,10 @@ async function canRespond(request, response, next) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isNaN(embed.max_chats_per_day) && Number(embed.max_chats_per_day) > 0) {
|
if (
|
||||||
|
!isNaN(embed.max_chats_per_day) &&
|
||||||
|
Number(embed.max_chats_per_day) > 0
|
||||||
|
) {
|
||||||
const dailyChatCount = await EmbedChats.count({
|
const dailyChatCount = await EmbedChats.count({
|
||||||
embed_id: embed.id,
|
embed_id: embed.id,
|
||||||
createdAt: {
|
createdAt: {
|
||||||
@ -141,6 +145,17 @@ async function canRespond(request, response, next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
next();
|
next();
|
||||||
|
} catch (e) {
|
||||||
|
response.status(500).json({
|
||||||
|
id: uuidv4(),
|
||||||
|
type: "abort",
|
||||||
|
textResponse: null,
|
||||||
|
sources: [],
|
||||||
|
close: true,
|
||||||
|
error: "Invalid request.",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
Loading…
Reference in New Issue
Block a user