Exception handler on embed chat middleware

This commit is contained in:
timothycarambat 2024-08-27 16:27:58 -07:00
parent 47a5c7126c
commit 548da9ade3

View File

@ -41,6 +41,7 @@ async function validEmbedConfigId(request, response, next) {
}
async function canRespond(request, response, next) {
try {
const embed = response.locals.embedConfig;
if (!embed) {
response.sendStatus(404).end();
@ -92,7 +93,10 @@ async function canRespond(request, response, next) {
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({
embed_id: embed.id,
createdAt: {
@ -141,6 +145,17 @@ async function canRespond(request, response, next) {
}
next();
} catch (e) {
response.status(500).json({
id: uuidv4(),
type: "abort",
textResponse: null,
sources: [],
close: true,
error: "Invalid request.",
});
return;
}
}
module.exports = {