Chore/consistent services and error handlers (#2101)

* Update index.ts

* Update buildChatflow.ts

* Update index.ts

* Update index.ts

* Update index.ts

* Update index.ts

* Update index.ts

* Update index.ts

* Update index.ts

* Update index.ts

* Consistency

* Rename ApiError to InternalServerError

* Use InternalFlowiseError in controllers

* Use InternalFlowiseError in services

* Catch routes without preconditioned parameters

* Reconfigure the route precondition checks

* Fix router precondition checks

* cleanup status codes, get proper error messages

---------

Co-authored-by: Henry <hzj94@hotmail.com>
This commit is contained in:
Octavian FlowiseAI
2024-04-11 03:11:01 -07:00
committed by GitHub
parent 024b2ad22e
commit d7194e8aaa
98 changed files with 862 additions and 651 deletions
+11 -14
View File
@@ -1,6 +1,6 @@
import { Request, Response, NextFunction } from 'express'
import { StatusCodes } from 'http-status-codes'
import { ApiError } from '../../errors/apiError'
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
import apikeyService from '../../services/apikey'
// Get api keys
@@ -15,8 +15,8 @@ const getAllApiKeys = async (req: Request, res: Response, next: NextFunction) =>
const createApiKey = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.body.keyName === 'undefined' || req.body.keyName === '') {
throw new ApiError(StatusCodes.PRECONDITION_FAILED, `Error: apikeyController.createApiKey - keyName not provided!`)
if (typeof req.body === 'undefined' || !req.body.keyName) {
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: apikeyController.createApiKey - keyName not provided!`)
}
const apiResponse = await apikeyService.createApiKey(req.body.keyName)
return res.json(apiResponse)
@@ -28,11 +28,11 @@ const createApiKey = async (req: Request, res: Response, next: NextFunction) =>
// Update api key
const updateApiKey = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.params.id === 'undefined' || req.params.id === '') {
new ApiError(StatusCodes.PRECONDITION_FAILED, `Error: apikeyController.updateApiKey - id not provided!`)
if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: apikeyController.updateApiKey - id not provided!`)
}
if (typeof req.body.keyName === 'undefined' || req.body.keyName === '') {
new ApiError(StatusCodes.PRECONDITION_FAILED, `Error: apikeyController.updateApiKey - keyName not provided!`)
if (typeof req.body === 'undefined' || !req.body.keyName) {
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: apikeyController.updateApiKey - keyName not provided!`)
}
const apiResponse = await apikeyService.updateApiKey(req.params.id, req.body.keyName)
return res.json(apiResponse)
@@ -44,8 +44,8 @@ const updateApiKey = async (req: Request, res: Response, next: NextFunction) =>
// Delete api key
const deleteApiKey = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.params.id === 'undefined' || req.params.id === '') {
new ApiError(StatusCodes.PRECONDITION_FAILED, `Error: apikeyController.deleteApiKey - id not provided!`)
if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: apikeyController.deleteApiKey - id not provided!`)
}
const apiResponse = await apikeyService.deleteApiKey(req.params.id)
return res.json(apiResponse)
@@ -57,13 +57,10 @@ const deleteApiKey = async (req: Request, res: Response, next: NextFunction) =>
// Verify api key
const verifyApiKey = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.params.apiKey === 'undefined' || req.params.apiKey === '') {
new ApiError(StatusCodes.PRECONDITION_FAILED, `Error: apikeyController.verifyApiKey - apiKey not provided!`)
if (typeof req.params === 'undefined' || !req.params.apiKey) {
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: apikeyController.verifyApiKey - apiKey not provided!`)
}
const apiResponse = await apikeyService.verifyApiKey(req.params.apiKey)
if (apiResponse.executionError) {
return res.status(apiResponse.status).send(apiResponse.msg)
}
return res.json(apiResponse)
} catch (error) {
next(error)
@@ -1,15 +1,17 @@
import { Request, Response, NextFunction } from 'express'
import assistantsService from '../../services/assistants'
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
import { StatusCodes } from 'http-status-codes'
const creatAssistant = async (req: Request, res: Response, next: NextFunction) => {
const createAssistant = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.body === 'undefined' || req.body === '') {
throw new Error(`Error: assistantsController.creatAssistant - body not provided!`)
}
const apiResponse = await assistantsService.creatAssistant(req.body)
if (apiResponse.executionError) {
return res.status(apiResponse.status).send(apiResponse.msg)
if (!req.body) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: assistantsController.createAssistant - body not provided!`
)
}
const apiResponse = await assistantsService.createAssistant(req.body)
return res.json(apiResponse)
} catch (error) {
next(error)
@@ -18,13 +20,13 @@ const creatAssistant = async (req: Request, res: Response, next: NextFunction) =
const deleteAssistant = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.params.id === 'undefined' || req.params.id === '') {
throw new Error(`Error: assistantsController.deleteAssistant - id not provided!`)
if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: assistantsController.deleteAssistant - id not provided!`
)
}
const apiResponse = await assistantsService.deleteAssistant(req.params.id, req.query.isDeleteBoth)
if (apiResponse.executionError) {
return res.status(apiResponse.status).send(apiResponse.msg)
}
return res.json(apiResponse)
} catch (error) {
next(error)
@@ -34,9 +36,6 @@ const deleteAssistant = async (req: Request, res: Response, next: NextFunction)
const getAllAssistants = async (req: Request, res: Response, next: NextFunction) => {
try {
const apiResponse = await assistantsService.getAllAssistants()
if (apiResponse.executionError) {
return res.status(apiResponse.status).send(apiResponse.msg)
}
return res.json(apiResponse)
} catch (error) {
next(error)
@@ -45,13 +44,13 @@ const getAllAssistants = async (req: Request, res: Response, next: NextFunction)
const getAssistantById = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.params.id === 'undefined' || req.params.id === '') {
throw new Error(`Error: assistantsController.getAssistantById - id not provided!`)
if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: assistantsController.getAssistantById - id not provided!`
)
}
const apiResponse = await assistantsService.getAssistantById(req.params.id)
if (apiResponse.executionError) {
return res.status(apiResponse.status).send(apiResponse.msg)
}
return res.json(apiResponse)
} catch (error) {
next(error)
@@ -60,16 +59,19 @@ const getAssistantById = async (req: Request, res: Response, next: NextFunction)
const updateAssistant = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.params.id === 'undefined' || req.params.id === '') {
throw new Error(`Error: assistantsController.updateAssistant - id not provided!`)
if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: assistantsController.updateAssistant - id not provided!`
)
}
if (typeof req.body === 'undefined' || req.body === '') {
throw new Error(`Error: assistantsController.updateAssistant - body not provided!`)
if (!req.body) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: assistantsController.updateAssistant - body not provided!`
)
}
const apiResponse = await assistantsService.updateAssistant(req.params.id, req.body)
if (apiResponse.executionError) {
return res.status(apiResponse.status).send(apiResponse.msg)
}
return res.json(apiResponse)
} catch (error) {
next(error)
@@ -77,7 +79,7 @@ const updateAssistant = async (req: Request, res: Response, next: NextFunction)
}
export default {
creatAssistant,
createAssistant,
deleteAssistant,
getAllAssistants,
getAssistantById,
@@ -6,11 +6,16 @@ import { clearSessionMemory } from '../../utils'
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
import { FindOptionsWhere } from 'typeorm'
import { ChatMessage } from '../../database/entities/ChatMessage'
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
import { StatusCodes } from 'http-status-codes'
const createChatMessage = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.body === 'undefined' || req.body === '') {
throw new Error('Error: chatMessagesController.createChatMessage - request body not provided!')
if (!req.body) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
'Error: chatMessagesController.createChatMessage - request body not provided!'
)
}
const apiResponse = await chatMessagesService.createChatMessage(req.body)
return res.json(apiResponse)
@@ -44,8 +49,11 @@ const getAllChatMessages = async (req: Request, res: Response, next: NextFunctio
const startDate = req.query?.startDate as string | undefined
const endDate = req.query?.endDate as string | undefined
const feedback = req.query?.feedback as boolean | undefined
if (typeof req.params.id === 'undefined' || req.params.id === '') {
throw new Error(`Error: chatMessageController.getAllChatMessages - id not provided!`)
if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: chatMessageController.getAllChatMessages - id not provided!`
)
}
const apiResponse = await chatMessagesService.getAllChatMessages(
req.params.id,
@@ -59,9 +67,6 @@ const getAllChatMessages = async (req: Request, res: Response, next: NextFunctio
messageId,
feedback
)
if (apiResponse.executionError) {
return res.status(apiResponse.status).send(apiResponse.msg)
}
return res.json(apiResponse)
} catch (error) {
next(error)
@@ -90,9 +95,6 @@ const getAllInternalChatMessages = async (req: Request, res: Response, next: Nex
messageId,
feedback
)
if (apiResponse.executionError) {
return res.status(apiResponse.status).send(apiResponse.msg)
}
return res.json(apiResponse)
} catch (error) {
next(error)
@@ -103,8 +105,11 @@ const getAllInternalChatMessages = async (req: Request, res: Response, next: Nex
const removeAllChatMessages = async (req: Request, res: Response, next: NextFunction) => {
try {
const appServer = getRunningExpressApp()
if (typeof req.params.id === 'undefined' || req.params.id === '') {
throw new Error('Error: chatMessagesController.removeAllChatMessages - id not provided!')
if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
'Error: chatMessagesController.removeAllChatMessages - id not provided!'
)
}
const chatflowid = req.params.id
const chatflow = await chatflowsService.getChatflowById(req.params.id)
@@ -139,9 +144,6 @@ const removeAllChatMessages = async (req: Request, res: Response, next: NextFunc
if (sessionId) deleteOptions.sessionId = sessionId
if (chatType) deleteOptions.chatType = chatType
const apiResponse = await chatMessagesService.removeAllChatMessages(chatId, chatflowid, deleteOptions)
if (apiResponse.executionError) {
res.status(apiResponse.status).send(apiResponse.msg)
}
return res.json(apiResponse)
} catch (error) {
next(error)
@@ -3,16 +3,18 @@ import chatflowsService from '../../services/chatflows'
import { ChatFlow } from '../../database/entities/ChatFlow'
import { createRateLimiter } from '../../utils/rateLimit'
import { getApiKey } from '../../utils/apiKey'
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
import { StatusCodes } from 'http-status-codes'
const checkIfChatflowIsValidForStreaming = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.params.id === 'undefined' || req.params.id === '') {
throw new Error(`Error: chatflowsRouter.checkIfChatflowIsValidForStreaming - id not provided!`)
if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: chatflowsRouter.checkIfChatflowIsValidForStreaming - id not provided!`
)
}
const apiResponse = await chatflowsService.checkIfChatflowIsValidForStreaming(req.params.id)
if (apiResponse.executionError) {
return res.status(apiResponse.status).send(apiResponse.msg)
}
return res.json(apiResponse)
} catch (error) {
next(error)
@@ -21,13 +23,13 @@ const checkIfChatflowIsValidForStreaming = async (req: Request, res: Response, n
const checkIfChatflowIsValidForUploads = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.params.id === 'undefined' || req.params.id === '') {
throw new Error(`Error: chatflowsRouter.checkIfChatflowIsValidForUploads - id not provided!`)
if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: chatflowsRouter.checkIfChatflowIsValidForUploads - id not provided!`
)
}
const apiResponse = await chatflowsService.checkIfChatflowIsValidForUploads(req.params.id)
if (apiResponse.executionError) {
return res.status(apiResponse.status).send(apiResponse.msg)
}
return res.json(apiResponse)
} catch (error) {
next(error)
@@ -36,8 +38,8 @@ const checkIfChatflowIsValidForUploads = async (req: Request, res: Response, nex
const deleteChatflow = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.params.id === 'undefined' || req.params.id === '') {
throw new Error(`Error: chatflowsRouter.deleteChatflow - id not provided!`)
if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: chatflowsRouter.deleteChatflow - id not provided!`)
}
const apiResponse = await chatflowsService.deleteChatflow(req.params.id)
return res.json(apiResponse)
@@ -58,17 +60,17 @@ const getAllChatflows = async (req: Request, res: Response, next: NextFunction)
// Get specific chatflow via api key
const getChatflowByApiKey = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.params.apiKey === 'undefined' || req.params.apiKey === '') {
throw new Error(`Error: chatflowsRouter.getChatflowById - apiKey not provided!`)
if (typeof req.params === 'undefined' || !req.params.apiKey) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: chatflowsRouter.getChatflowByApiKey - apiKey not provided!`
)
}
const apiKey = await getApiKey(req.params.apiKey)
if (!apiKey) {
return res.status(401).send('Unauthorized')
}
const apiResponse = await chatflowsService.getChatflowByApiKey(apiKey.id)
if (apiResponse.executionError) {
return res.status(apiResponse.status).send(apiResponse.msg)
}
return res.json(apiResponse)
} catch (error) {
next(error)
@@ -77,13 +79,10 @@ const getChatflowByApiKey = async (req: Request, res: Response, next: NextFuncti
const getChatflowById = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.params.id === 'undefined' || req.params.id === '') {
throw new Error(`Error: chatflowsRouter.getChatflowById - id not provided!`)
if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: chatflowsRouter.getChatflowById - id not provided!`)
}
const apiResponse = await chatflowsService.getChatflowById(req.params.id)
if (apiResponse.executionError) {
return res.status(apiResponse.status).send(apiResponse.msg)
}
return res.json(apiResponse)
} catch (error) {
next(error)
@@ -92,8 +91,8 @@ const getChatflowById = async (req: Request, res: Response, next: NextFunction)
const saveChatflow = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.body === 'undefined' || req.body === '') {
throw new Error(`Error: chatflowsRouter.saveChatflow - body not provided!`)
if (!req.body) {
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: chatflowsRouter.saveChatflow - body not provided!`)
}
const body = req.body
const newChatFlow = new ChatFlow()
@@ -107,8 +106,8 @@ const saveChatflow = async (req: Request, res: Response, next: NextFunction) =>
const updateChatflow = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.params.id === 'undefined' || req.params.id === '') {
throw new Error(`Error: chatflowsRouter.updateChatflow - id not provided!`)
if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: chatflowsRouter.updateChatflow - id not provided!`)
}
const chatflow = await chatflowsService.getChatflowById(req.params.id)
if (!chatflow) {
@@ -131,13 +130,13 @@ const updateChatflow = async (req: Request, res: Response, next: NextFunction) =
const getSinglePublicChatflow = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.params.id === 'undefined' || req.params.id === '') {
throw new Error(`Error: chatflowsRouter.updateChatflow - id not provided!`)
if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: chatflowsRouter.getSinglePublicChatflow - id not provided!`
)
}
const apiResponse = await chatflowsService.getSinglePublicChatflow(req.params.id)
if (apiResponse.executionError) {
return res.status(apiResponse.status).send(apiResponse.msg)
}
return res.json(apiResponse)
} catch (error) {
next(error)
@@ -146,13 +145,13 @@ const getSinglePublicChatflow = async (req: Request, res: Response, next: NextFu
const getSinglePublicChatbotConfig = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.params.id === 'undefined' || req.params.id === '') {
throw new Error(`Error: chatflowsRouter.getSinglePublicChatbotConfig - id not provided!`)
if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: chatflowsRouter.getSinglePublicChatbotConfig - id not provided!`
)
}
const apiResponse = await chatflowsService.getSinglePublicChatbotConfig(req.params.id)
if (apiResponse.executionError) {
return res.status(apiResponse.status).send(apiResponse.msg)
}
return res.json(apiResponse)
} catch (error) {
next(error)
@@ -1,5 +1,7 @@
import { Request, Response, NextFunction } from 'express'
import componentsCredentialsService from '../../services/components-credentials'
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
import { StatusCodes } from 'http-status-codes'
// Get all component credentials
const getAllComponentsCredentials = async (req: Request, res: Response, next: NextFunction) => {
@@ -14,8 +16,11 @@ const getAllComponentsCredentials = async (req: Request, res: Response, next: Ne
// Get component credential via name
const getComponentByName = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.params.name === 'undefined' || req.params.name === '') {
throw new Error(`Error: componentsCredentialsController.getComponentByName - name not provided!`)
if (typeof req.params === 'undefined' || !req.params.name) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: componentsCredentialsController.getComponentByName - name not provided!`
)
}
const apiResponse = await componentsCredentialsService.getComponentByName(req.params.name)
return res.json(apiResponse)
@@ -27,8 +32,11 @@ const getComponentByName = async (req: Request, res: Response, next: NextFunctio
// Returns specific component credential icon via name
const getSingleComponentsCredentialIcon = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.params.name === 'undefined' || req.params.name === '') {
throw new Error(`Error: componentsCredentialsController.getSingleComponentsCredentialIcon - name not provided!`)
if (typeof req.params === 'undefined' || !req.params.name) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: componentsCredentialsController.getSingleComponentsCredentialIcon - name not provided!`
)
}
const apiResponse = await componentsCredentialsService.getSingleComponentsCredentialIcon(req.params.name)
return res.sendFile(apiResponse)
@@ -1,10 +1,15 @@
import { Request, Response, NextFunction } from 'express'
import credentialsService from '../../services/credentials'
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
import { StatusCodes } from 'http-status-codes'
const createCredential = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.body === 'undefined' || req.body === '') {
throw new Error(`Error: credentialsController.createCredential - body not provided!`)
if (!req.body) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: credentialsController.createCredential - body not provided!`
)
}
const apiResponse = await credentialsService.createCredential(req.body)
return res.json(apiResponse)
@@ -15,13 +20,13 @@ const createCredential = async (req: Request, res: Response, next: NextFunction)
const deleteCredentials = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.params.id === 'undefined' || req.params.id === '') {
throw new Error(`Error: credentialsController.deleteCredentials - id not provided!`)
if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: credentialsController.deleteCredentials - id not provided!`
)
}
const apiResponse = await credentialsService.deleteCredentials(req.params.id)
if (apiResponse.executionError) {
return res.status(apiResponse.status).send(apiResponse.msg)
}
return res.json(apiResponse)
} catch (error) {
next(error)
@@ -39,13 +44,13 @@ const getAllCredentials = async (req: Request, res: Response, next: NextFunction
const getCredentialById = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.params.id === 'undefined' || req.params.id === '') {
throw new Error(`Error: credentialsController.getCredentialById - id not provided!`)
if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: credentialsController.getCredentialById - id not provided!`
)
}
const apiResponse = await credentialsService.getCredentialById(req.params.id)
if (apiResponse.executionError) {
return res.status(apiResponse.status).send(apiResponse.msg)
}
return res.json(apiResponse)
} catch (error) {
next(error)
@@ -54,16 +59,19 @@ const getCredentialById = async (req: Request, res: Response, next: NextFunction
const updateCredential = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.params.id === 'undefined' || req.params.id === '') {
throw new Error(`Error: credentialsController.updateCredential - id not provided!`)
if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: credentialsController.updateCredential - id not provided!`
)
}
if (typeof req.body === 'undefined' || req.body === '') {
throw new Error(`Error: credentialsController.updateCredential - body not provided!`)
if (!req.body) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: credentialsController.updateCredential - body not provided!`
)
}
const apiResponse = await credentialsService.updateCredential(req.params.id, req.body)
if (apiResponse.executionError) {
return res.status(apiResponse.status).send(apiResponse.msg)
}
return res.json(apiResponse)
} catch (error) {
next(error)
@@ -1,10 +1,15 @@
import { Request, Response, NextFunction } from 'express'
import feedbackService from '../../services/feedback'
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
import { StatusCodes } from 'http-status-codes'
const getAllChatMessageFeedback = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.params.id === 'undefined' || req.params.id === '') {
throw new Error(`Error: feedbackController.getAllChatMessageFeedback - id not provided!`)
if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: feedbackController.getAllChatMessageFeedback - id not provided!`
)
}
const chatflowid = req.params.id
const chatId = req.query?.chatId as string | undefined
@@ -20,8 +25,11 @@ const getAllChatMessageFeedback = async (req: Request, res: Response, next: Next
const createChatMessageFeedbackForChatflow = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.body === 'undefined' || req.body === '') {
throw new Error(`Error: feedbackController.createChatMessageFeedbackForChatflow - body not provided!`)
if (!req.body) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: feedbackController.createChatMessageFeedbackForChatflow - body not provided!`
)
}
const apiResponse = await feedbackService.createChatMessageFeedbackForChatflow(req.body)
return res.json(apiResponse)
@@ -32,11 +40,17 @@ const createChatMessageFeedbackForChatflow = async (req: Request, res: Response,
const updateChatMessageFeedbackForChatflow = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.body === 'undefined' || req.body === '') {
throw new Error(`Error: feedbackController.updateChatMessageFeedbackForChatflow - body not provided!`)
if (!req.body) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: feedbackController.updateChatMessageFeedbackForChatflow - body not provided!`
)
}
if (typeof req.params.id === 'undefined' || req.params.id === '') {
throw new Error(`Error: feedbackController.updateChatMessageFeedbackForChatflow - id not provided!`)
if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: feedbackController.updateChatMessageFeedbackForChatflow - id not provided!`
)
}
const apiResponse = await feedbackService.updateChatMessageFeedbackForChatflow(req.params.id, req.body)
return res.json(apiResponse)
@@ -1,25 +1,27 @@
import { Request, Response, NextFunction } from 'express'
import fetchLinksService from '../../services/fetch-links'
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
import { StatusCodes } from 'http-status-codes'
const getAllLinks = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.query.url === 'undefined' || req.query.url === '') {
throw new Error(`Error: fetchLinksController.getAllLinks - url not provided!`)
if (typeof req.query === 'undefined' || !req.query.url) {
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: fetchLinksController.getAllLinks - url not provided!`)
}
if (typeof req.query.relativeLinksMethod === 'undefined' || req.query.relativeLinksMethod === '') {
throw new Error(`Error: fetchLinksController.getAllLinks - relativeLinksMethod not provided!`)
if (typeof req.query === 'undefined' || !req.query.relativeLinksMethod) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: fetchLinksController.getAllLinks - relativeLinksMethod not provided!`
)
}
if (typeof req.query.limit === 'undefined' || req.query.limit === '') {
throw new Error(`Error: fetchLinksController.getAllLinks - limit not provided!`)
if (typeof req.query === 'undefined' || !req.query.limit) {
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: fetchLinksController.getAllLinks - limit not provided!`)
}
const apiResponse = await fetchLinksService.getAllLinks(
req.query.url as string,
req.query.relativeLinksMethod as string,
req.query.limit as string
)
if (apiResponse.executionError) {
return res.status(apiResponse.status).send(apiResponse.msg)
}
return res.json(apiResponse)
} catch (error) {
next(error)
@@ -1,15 +1,17 @@
import { Request, Response, NextFunction } from 'express'
import flowConfigsService from '../../services/flow-configs'
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
import { StatusCodes } from 'http-status-codes'
const getSingleFlowConfig = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.params.id === 'undefined' || req.params.id === '') {
throw new Error(`Error: flowConfigsController.getSingleFlowConfig - id not provided!`)
if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: flowConfigsController.getSingleFlowConfig - id not provided!`
)
}
const apiResponse = await flowConfigsService.getSingleFlowConfig(req.params.id)
if (apiResponse.executionError) {
return res.status(apiResponse.status).send(apiResponse.msg)
}
return res.json(apiResponse)
} catch (error) {
next(error)
+6 -1
View File
@@ -1,10 +1,15 @@
import { Request, Response, NextFunction } from 'express'
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
import { StatusCodes } from 'http-status-codes'
// Configure number of proxies in Host Environment
const configureProxyNrInHostEnv = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.ip === 'undefined' || req.ip) {
throw new Error(`Error: ipController.configureProxyNrInHostEnv - ip not provided!`)
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: ipController.configureProxyNrInHostEnv - ip not provided!`
)
}
const apiResponse = {
ip: req.ip,
@@ -1,15 +1,17 @@
import { Request, Response, NextFunction } from 'express'
import loadPromptsService from '../../services/load-prompts'
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
import { StatusCodes } from 'http-status-codes'
const createPrompt = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.body === 'undefined' || typeof req.body.promptName === 'undefined' || req.body.promptName === '') {
throw new Error(`Error: loadPromptsController.createPrompt - promptName not provided!`)
if (typeof req.body === 'undefined' || !req.body.promptName) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: loadPromptsController.createPrompt - promptName not provided!`
)
}
const apiResponse = await loadPromptsService.createPrompt(req.body.promptName as string)
if (apiResponse.executionError) {
return res.status(apiResponse.status).send(apiResponse.msg)
}
return res.json(apiResponse)
} catch (error) {
next(error)
@@ -1,10 +1,15 @@
import { Request, Response, NextFunction } from 'express'
import nodeConfigsService from '../../services/node-configs'
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
import { StatusCodes } from 'http-status-codes'
const getAllNodeConfigs = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.body === 'undefined' || req.body === '') {
throw new Error(`Error: nodeConfigsController.getAllNodeConfigs - body not provided!`)
if (!req.body) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: nodeConfigsController.getAllNodeConfigs - body not provided!`
)
}
const apiResponse = await nodeConfigsService.getAllNodeConfigs(req.body)
return res.json(apiResponse)
@@ -1,5 +1,7 @@
import { Request, Response, NextFunction } from 'express'
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
import { StatusCodes } from 'http-status-codes'
// Returns specific component node icon via name
const getSingleNodeIcon = async (req: Request, res: Response, next: NextFunction) => {
@@ -8,17 +10,26 @@ const getSingleNodeIcon = async (req: Request, res: Response, next: NextFunction
if (Object.prototype.hasOwnProperty.call(appServer.nodesPool.componentNodes, req.params.name)) {
const nodeInstance = appServer.nodesPool.componentNodes[req.params.name]
if (nodeInstance.icon === undefined) {
throw new Error(`Error: nodeIconController.getSingleNodeIcon - Node ${req.params.name} icon not found`)
throw new InternalFlowiseError(
StatusCodes.NOT_FOUND,
`Error: nodeIconController.getSingleNodeIcon - Node ${req.params.name} icon not found`
)
}
if (nodeInstance.icon.endsWith('.svg') || nodeInstance.icon.endsWith('.png') || nodeInstance.icon.endsWith('.jpg')) {
const filepath = nodeInstance.icon
res.sendFile(filepath)
} else {
throw new Error(`Error: nodeIconController.getSingleNodeIcon - Node ${req.params.name} icon is missing icon`)
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: nodeIconController.getSingleNodeIcon - Node ${req.params.name} icon is missing icon`
)
}
} else {
throw new Error(`Error: nodeIconController.getSingleNodeIcon - Node ${req.params.name} not found`)
throw new InternalFlowiseError(
StatusCodes.NOT_FOUND,
`Error: nodeIconController.getSingleNodeIcon - Node ${req.params.name} not found`
)
}
} catch (error) {
next(error)
+21 -16
View File
@@ -1,5 +1,7 @@
import { Request, Response, NextFunction } from 'express'
import nodesService from '../../services/nodes'
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
import { StatusCodes } from 'http-status-codes'
const getAllNodes = async (req: Request, res: Response, next: NextFunction) => {
try {
@@ -12,8 +14,8 @@ const getAllNodes = async (req: Request, res: Response, next: NextFunction) => {
const getNodeByName = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.params.name === 'undefined' || req.params.name === '') {
throw new Error(`Error: nodesController.getNodeByName - name not provided!`)
if (typeof req.params === 'undefined' || !req.params.name) {
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: nodesController.getNodeByName - name not provided!`)
}
const apiResponse = await nodesService.getNodeByName(req.params.name)
return res.json(apiResponse)
@@ -24,8 +26,8 @@ const getNodeByName = async (req: Request, res: Response, next: NextFunction) =>
const getSingleNodeIcon = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.params.name === 'undefined' || req.params.name === '') {
throw new Error(`Error: nodesController.getSingleNodeIcon - name not provided!`)
if (typeof req.params === 'undefined' || !req.params.name) {
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: nodesController.getSingleNodeIcon - name not provided!`)
}
const apiResponse = await nodesService.getSingleNodeIcon(req.params.name)
return res.sendFile(apiResponse)
@@ -36,16 +38,19 @@ const getSingleNodeIcon = async (req: Request, res: Response, next: NextFunction
const getSingleNodeAsyncOptions = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.body === 'undefined' || req.body === '') {
throw new Error(`Error: nodesController.getSingleNodeAsyncOptions - body not provided!`)
if (!req.body) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: nodesController.getSingleNodeAsyncOptions - body not provided!`
)
}
if (typeof req.params.name === 'undefined' || req.params.name === '') {
throw new Error(`Error: nodesController.getSingleNodeAsyncOptions - name not provided!`)
if (typeof req.params === 'undefined' || !req.params.name) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: nodesController.getSingleNodeAsyncOptions - name not provided!`
)
}
const apiResponse = await nodesService.getSingleNodeAsyncOptions(req.params.name, req.body)
if (apiResponse.executionError) {
return res.status(apiResponse.status).send(apiResponse.msg)
}
return res.json(apiResponse)
} catch (error) {
next(error)
@@ -54,13 +59,13 @@ const getSingleNodeAsyncOptions = async (req: Request, res: Response, next: Next
const executeCustomFunction = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.body === 'undefined' || req.body === '') {
throw new Error(`Error: nodesController.executeCustomFunction - body not provided!`)
if (!req.body) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: nodesController.executeCustomFunction - body not provided!`
)
}
const apiResponse = await nodesService.executeCustomFunction(req.body)
if (apiResponse.executionError) {
return res.status(apiResponse.status).send(apiResponse.msg)
}
return res.json(apiResponse)
} catch (error) {
next(error)
@@ -4,17 +4,19 @@ import * as fs from 'fs'
import openaiAssistantsService from '../../services/openai-assistants'
import { getUserHome } from '../../utils'
import contentDisposition from 'content-disposition'
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
import { StatusCodes } from 'http-status-codes'
// List available assistants
const getAllOpenaiAssistants = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.query.credential === 'undefined' || req.query.credential === '') {
throw new Error(`Error: openaiAssistantsController.getAllOpenaiAssistants - credential not provided!`)
if (typeof req.query === 'undefined' || !req.query.credential) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: openaiAssistantsController.getAllOpenaiAssistants - credential not provided!`
)
}
const apiResponse = await openaiAssistantsService.getAllOpenaiAssistants(req.query.credential as string)
if (apiResponse.executionError) {
return res.status(apiResponse.status).send(apiResponse.msg)
}
return res.json(apiResponse)
} catch (error) {
next(error)
@@ -24,16 +26,19 @@ const getAllOpenaiAssistants = async (req: Request, res: Response, next: NextFun
// Get assistant object
const getSingleOpenaiAssistant = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.params.id === 'undefined' || req.params.id === '') {
throw new Error(`Error: openaiAssistantsController.getSingleOpenaiAssistant - id not provided!`)
if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: openaiAssistantsController.getSingleOpenaiAssistant - id not provided!`
)
}
if (typeof req.query.credential === 'undefined' || req.query.credential === '') {
throw new Error(`Error: openaiAssistantsController.getSingleOpenaiAssistant - credential not provided!`)
if (typeof req.query === 'undefined' || !req.query.credential) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: openaiAssistantsController.getSingleOpenaiAssistant - credential not provided!`
)
}
const apiResponse = await openaiAssistantsService.getSingleOpenaiAssistant(req.query.credential as string, req.params.id)
if (apiResponse.executionError) {
return res.status(apiResponse.status).send(apiResponse.msg)
}
return res.json(apiResponse)
} catch (error) {
next(error)
@@ -2,20 +2,28 @@ import { Request, Response, NextFunction } from 'express'
import { getRateLimiter } from '../../utils/rateLimit'
import chatflowsService from '../../services/chatflows'
import logger from '../../utils/logger'
import { utilBuildChatflow } from '../../utils/buildChatflow'
import predictionsServices from '../../services/predictions'
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
import { StatusCodes } from 'http-status-codes'
// Send input message and get prediction result (External)
const createPrediction = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.params.id === 'undefined' || req.params.id === '') {
throw new Error(`Error: predictionsController.createPrediction - id not provided!`)
if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: predictionsController.createPrediction - id not provided!`
)
}
if (typeof req.body === 'undefined' || req.body === '') {
throw new Error(`Error: predictionsController.createPrediction - body not provided!`)
if (!req.body) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: predictionsController.createPrediction - body not provided!`
)
}
const chatflow = await chatflowsService.getChatflowById(req.params.id)
if (!chatflow) {
return res.status(404).send(`Chatflow ${req.params.id} not found`)
throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Chatflow ${req.params.id} not found`)
}
let isDomainAllowed = true
logger.info(`[server]: Request originated from ${req.headers.origin}`)
@@ -37,15 +45,12 @@ const createPrediction = async (req: Request, res: Response, next: NextFunction)
}).length > 0
}
}
if (isDomainAllowed) {
const apiResponse = await utilBuildChatflow(req, req.io)
if (apiResponse.executionError) {
return res.status(apiResponse.status).send(apiResponse.msg)
}
//@ts-ignore
const apiResponse = await predictionsServices.buildChatflow(req, req?.io)
return res.json(apiResponse)
} else {
return res.status(401).send(`This site is not allowed to access this chatbot`)
throw new InternalFlowiseError(StatusCodes.UNAUTHORIZED, `This site is not allowed to access this chatbot`)
}
} catch (error) {
next(error)
@@ -1,11 +1,14 @@
import { StatusCodes } from 'http-status-codes'
import { Request, Response, NextFunction } from 'express'
import statsService from '../../services/stats'
import { chatType } from '../../Interface'
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
import { getErrorMessage } from '../../errors/utils'
const getChatflowStats = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.params.id === 'undefined' || req.params.id === '') {
throw new Error(`Error: statsController.getChatflowStats - id not provided!`)
if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: statsController.getChatflowStats - id not provided!`)
}
const chatflowid = req.params.id
let chatTypeFilter = req.query?.chatType as chatType | undefined
@@ -22,13 +25,13 @@ const getChatflowStats = async (req: Request, res: Response, next: NextFunction)
chatTypeFilter = chatType.INTERNAL
}
} catch (e) {
return res.status(500).send(e)
throw new InternalFlowiseError(
StatusCodes.INTERNAL_SERVER_ERROR,
`Error: statsController.getChatflowStats - ${getErrorMessage(e)}`
)
}
}
const apiResponse = await statsService.getChatflowStats(chatflowid, chatTypeFilter, startDate, endDate, '', true)
if (apiResponse.executionError) {
return res.status(apiResponse.status).send(apiResponse.msg)
}
return res.json(apiResponse)
} catch (error) {
next(error)
+15 -28
View File
@@ -1,15 +1,14 @@
import { Request, Response, NextFunction } from 'express'
import toolsService from '../../services/tools'
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
import { StatusCodes } from 'http-status-codes'
const creatTool = async (req: Request, res: Response, next: NextFunction) => {
const createTool = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.body === 'undefined' || req.body === '') {
throw new Error(`Error: toolsController.creatTool - body not provided!`)
}
const apiResponse = await toolsService.creatTool(req.body)
if (apiResponse.executionError) {
return res.status(apiResponse.status).send(apiResponse.msg)
if (!req.body) {
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: toolsController.createTool - body not provided!`)
}
const apiResponse = await toolsService.createTool(req.body)
return res.json(apiResponse)
} catch (error) {
next(error)
@@ -18,13 +17,10 @@ const creatTool = async (req: Request, res: Response, next: NextFunction) => {
const deleteTool = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.params.id === 'undefined' || req.params.id === '') {
throw new Error(`Error: toolsController.deleteTool - id not provided!`)
if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: toolsController.deleteTool - id not provided!`)
}
const apiResponse = await toolsService.deleteTool(req.params.id)
if (apiResponse.executionError) {
return res.status(apiResponse.status).send(apiResponse.msg)
}
return res.json(apiResponse)
} catch (error) {
next(error)
@@ -34,9 +30,6 @@ const deleteTool = async (req: Request, res: Response, next: NextFunction) => {
const getAllTools = async (req: Request, res: Response, next: NextFunction) => {
try {
const apiResponse = await toolsService.getAllTools()
if (apiResponse.executionError) {
return res.status(apiResponse.status).send(apiResponse.msg)
}
return res.json(apiResponse)
} catch (error) {
next(error)
@@ -45,13 +38,10 @@ const getAllTools = async (req: Request, res: Response, next: NextFunction) => {
const getToolById = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.params.id === 'undefined' || req.params.id === '') {
throw new Error(`Error: toolsController.getToolById - id not provided!`)
if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: toolsController.getToolById - id not provided!`)
}
const apiResponse = await toolsService.getToolById(req.params.id)
if (apiResponse.executionError) {
return res.status(apiResponse.status).send(apiResponse.msg)
}
return res.json(apiResponse)
} catch (error) {
next(error)
@@ -60,16 +50,13 @@ const getToolById = async (req: Request, res: Response, next: NextFunction) => {
const updateTool = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.params.id === 'undefined' || req.params.id === '') {
throw new Error(`Error: toolsController.updateTool - id not provided!`)
if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: toolsController.updateTool - id not provided!`)
}
if (typeof req.body === 'undefined' || req.body === '') {
throw new Error(`Error: toolsController.deleteTool - body not provided!`)
if (!req.body) {
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: toolsController.deleteTool - body not provided!`)
}
const apiResponse = await toolsService.updateTool(req.params.id, req.body)
if (apiResponse.executionError) {
return res.status(apiResponse.status).send(apiResponse.msg)
}
return res.json(apiResponse)
} catch (error) {
next(error)
@@ -77,7 +64,7 @@ const updateTool = async (req: Request, res: Response, next: NextFunction) => {
}
export default {
creatTool,
createTool,
deleteTool,
getAllTools,
getToolById,
@@ -1,11 +1,16 @@
import { Request, Response, NextFunction } from 'express'
import variablesService from '../../services/variables'
import { Variable } from '../../database/entities/Variable'
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
import { StatusCodes } from 'http-status-codes'
const createVariable = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.body === 'undefined') {
throw new Error(`Error: variablesController.createVariable - body not provided!`)
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: variablesController.createVariable - body not provided!`
)
}
const body = req.body
const newVariable = new Variable()
@@ -19,8 +24,8 @@ const createVariable = async (req: Request, res: Response, next: NextFunction) =
const deleteVariable = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.params.id === 'undefined' || req.params.id === '') {
throw new Error('Error: variablesController.deleteVariable - id not provided!')
if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, 'Error: variablesController.deleteVariable - id not provided!')
}
const apiResponse = await variablesService.deleteVariable(req.params.id)
return res.json(apiResponse)
@@ -40,11 +45,14 @@ const getAllVariables = async (req: Request, res: Response, next: NextFunction)
const updateVariable = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.params.id === 'undefined' || req.params.id === '') {
throw new Error('Error: variablesController.updateVariable - id not provided!')
if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, 'Error: variablesController.updateVariable - id not provided!')
}
if (typeof req.body === 'undefined') {
throw new Error('Error: variablesController.updateVariable - body not provided!')
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
'Error: variablesController.updateVariable - body not provided!'
)
}
const variable = await variablesService.getVariableById(req.params.id)
if (!variable) {
@@ -12,7 +12,8 @@ const getRateLimiterMiddleware = async (req: Request, res: Response, next: NextF
const upsertVectorMiddleware = async (req: Request, res: Response, next: NextFunction) => {
try {
return await vectorsService.upsertVectorMiddleware(req, res)
const apiResponse = await vectorsService.upsertVectorMiddleware(req)
return res.json(apiResponse)
} catch (error) {
next(error)
}
@@ -20,7 +21,9 @@ const upsertVectorMiddleware = async (req: Request, res: Response, next: NextFun
const createInternalUpsert = async (req: Request, res: Response, next: NextFunction) => {
try {
return await vectorsService.upsertVectorMiddleware(req, res, true)
const isInternal = true
const apiResponse = await vectorsService.upsertVectorMiddleware(req, isInternal)
return res.json(apiResponse)
} catch (error) {
next(error)
}
@@ -4,9 +4,6 @@ import versionsService from '../../services/versions'
const getVersion = async (req: Request, res: Response, next: NextFunction) => {
try {
const apiResponse = await versionsService.getVersion()
if (apiResponse.executionError) {
return res.status(apiResponse.status).send(apiResponse.msg)
}
return res.json(apiResponse)
} catch (error) {
next(error)