From 1c9ef3cb76bd6513bc35de79a13f8cd894d3abb7 Mon Sep 17 00:00:00 2001
From: Octavian FlowiseAI <154992625+ocflowiseai@users.noreply.github.com>
Date: Thu, 4 Apr 2024 12:54:13 +0200
Subject: [PATCH 01/18] Update index.ts
---
.../server/src/services/chatflows/index.ts | 82 +++++--------------
1 file changed, 22 insertions(+), 60 deletions(-)
diff --git a/packages/server/src/services/chatflows/index.ts b/packages/server/src/services/chatflows/index.ts
index 78c5c695e5b..ecd86b42422 100644
--- a/packages/server/src/services/chatflows/index.ts
+++ b/packages/server/src/services/chatflows/index.ts
@@ -1,4 +1,6 @@
import path from 'path'
+import { StatusCodes } from 'http-status-codes'
+import { ApiError } from '../../errors/apiError'
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
import { IChatFlow } from '../../Interface'
import { ChatFlow } from '../../database/entities/ChatFlow'
@@ -27,11 +29,7 @@ const checkIfChatflowIsValidForStreaming = async (chatflowId: string): Promise endingNodeIds.includes(nd.id))
@@ -58,11 +52,7 @@ const checkIfChatflowIsValidForStreaming = async (chatflowId: string): Promise => {
}
return dbResponse
} catch (error) {
- throw new Error(`Error: chatflowsService.getAllChatflows - ${error}`)
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.getAllChatflows - ${error}`)
}
}
@@ -135,7 +121,7 @@ const getAllChatflows = async (): Promise => {
const dbResponse = await appServer.AppDataSource.getRepository(ChatFlow).find()
return dbResponse
} catch (error) {
- throw new Error(`Error: chatflowsService.getAllChatflows - ${error}`)
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.getAllChatflows - ${error}`)
}
}
@@ -150,15 +136,11 @@ const getChatflowByApiKey = async (apiKeyId: string): Promise => {
.orderBy('cf.name', 'ASC')
.getMany()
if (dbResponse.length < 1) {
- return {
- executionError: true,
- status: 404,
- msg: `Chatflow not found in the database!`
- }
+ throw new ApiError(StatusCodes.NOT_FOUND, `Chatflow not found in the database!`)
}
return dbResponse
} catch (error) {
- throw new Error(`Error: chatflowsService.getChatflowByApiKey - ${error}`)
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.getChatflowByApiKey - ${error}`)
}
}
@@ -169,15 +151,11 @@ const getChatflowById = async (chatflowId: string): Promise => {
id: chatflowId
})
if (!dbResponse) {
- return {
- executionError: true,
- status: 404,
- msg: `Chatflow ${chatflowId} not found in the database!`
- }
+ throw new ApiError(StatusCodes.NOT_FOUND, `Chatflow ${chatflowId} not found in the database!`)
}
return dbResponse
} catch (error) {
- throw new Error(`Error: chatflowsService.getAllChatflows - ${error}`)
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.getAllChatflows - ${error}`)
}
}
@@ -193,7 +171,7 @@ const saveChatflow = async (newChatFlow: ChatFlow): Promise => {
})
return dbResponse
} catch (error) {
- throw new Error(`Error: chatflowsService.saveChatflow - ${error}`)
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.saveChatflow - ${error}`)
}
}
@@ -210,7 +188,7 @@ const updateChatflow = async (chatflow: ChatFlow, updateChatFlow: ChatFlow): Pro
}
return dbResponse
} catch (error) {
- throw new Error(`Error: chatflowsService.updateChatflow - ${error}`)
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.updateChatflow - ${error}`)
}
}
@@ -224,19 +202,11 @@ const getSinglePublicChatflow = async (chatflowId: string): Promise => {
if (dbResponse && dbResponse.isPublic) {
return dbResponse
} else if (dbResponse && !dbResponse.isPublic) {
- return {
- executionError: true,
- status: 401,
- msg: `Unauthorized`
- }
- }
- return {
- executionError: true,
- status: 404,
- msg: `Chatflow ${chatflowId} not found`
+ throw new ApiError(StatusCodes.UNAUTHORIZED, `Unauthorized`)
}
+ throw new ApiError(StatusCodes.NOT_FOUND, `Chatflow ${chatflowId} not found`)
} catch (error) {
- throw new Error(`Error: chatflowsService.getSinglePublicChatflow - ${error}`)
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.getSinglePublicChatflow - ${error}`)
}
}
@@ -249,11 +219,7 @@ const getSinglePublicChatbotConfig = async (chatflowId: string): Promise =>
id: chatflowId
})
if (!dbResponse) {
- return {
- executionError: true,
- status: 404,
- msg: `Chatflow ${chatflowId} not found`
- }
+ throw new ApiError(StatusCodes.NOT_FOUND, `Chatflow ${chatflowId} not found`)
}
const uploadsConfig = await utilGetUploadsConfig(chatflowId)
// even if chatbotConfig is not set but uploads are enabled
@@ -263,16 +229,12 @@ const getSinglePublicChatbotConfig = async (chatflowId: string): Promise =>
const parsedConfig = dbResponse.chatbotConfig ? JSON.parse(dbResponse.chatbotConfig) : {}
return { ...parsedConfig, uploads: uploadsConfig }
} catch (e) {
- return {
- executionError: true,
- status: 500,
- msg: `Error parsing Chatbot Config for Chatflow ${chatflowId}`
- }
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error parsing Chatbot Config for Chatflow ${chatflowId}`)
}
}
return 'OK'
} catch (error) {
- throw new Error(`Error: chatflowsService.getSinglePublicChatbotConfig - ${error}`)
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.getSinglePublicChatbotConfig - ${error}`)
}
}
From 6d6589a2123293f8659dedcb957bd107159ef924 Mon Sep 17 00:00:00 2001
From: Octavian FlowiseAI <154992625+ocflowiseai@users.noreply.github.com>
Date: Thu, 4 Apr 2024 12:56:16 +0200
Subject: [PATCH 02/18] Update buildChatflow.ts
---
packages/server/src/utils/buildChatflow.ts | 52 +++++-----------------
1 file changed, 12 insertions(+), 40 deletions(-)
diff --git a/packages/server/src/utils/buildChatflow.ts b/packages/server/src/utils/buildChatflow.ts
index b1043cc4466..c7e35cc9249 100644
--- a/packages/server/src/utils/buildChatflow.ts
+++ b/packages/server/src/utils/buildChatflow.ts
@@ -3,6 +3,7 @@ import { IFileUpload, getStoragePath, convertSpeechToText, ICommonObject } from
import { StatusCodes } from 'http-status-codes'
import { IncomingInput, IMessage, INodeData, IReactFlowObject, IReactFlowNode, IDepthQueue, chatType, IChatMessage } from '../Interface'
import path from 'path'
+import { ApiError } from '../errors/apiError'
import { ChatFlow } from '../database/entities/ChatFlow'
import { Server } from 'socket.io'
import { getRunningExpressApp } from '../utils/getRunningExpressApp'
@@ -47,11 +48,7 @@ export const utilBuildChatflow = async (req: Request, socketIO?: Server, isInter
id: chatflowid
})
if (!chatflow) {
- return {
- executionError: true,
- status: StatusCodes.NOT_FOUND,
- msg: `Chatflow ${chatflowid} not found`
- }
+ throw new ApiError(StatusCodes.NOT_FOUND, `Chatflow ${chatflowid} not found`)
}
const chatId = incomingInput.chatId ?? incomingInput.overrideConfig?.sessionId ?? uuidv4()
@@ -60,11 +57,7 @@ export const utilBuildChatflow = async (req: Request, socketIO?: Server, isInter
if (!isInternal) {
const isKeyValidated = await utilValidateKey(req, chatflow)
if (!isKeyValidated) {
- return {
- executionError: true,
- status: StatusCodes.UNAUTHORIZED,
- msg: `Unauthorized`
- }
+ throw new ApiError(StatusCodes.UNAUTHORIZED, `Unauthorized`)
}
}
@@ -189,11 +182,7 @@ export const utilBuildChatflow = async (req: Request, socketIO?: Server, isInter
const directedGraph = graph
const endingNodeIds = getEndingNodes(nodeDependencies, directedGraph)
if (!endingNodeIds.length) {
- return {
- executionError: true,
- status: 500,
- msg: `Ending nodes not found`
- }
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Ending nodes not found`)
}
const endingNodes = nodes.filter((nd) => endingNodeIds.includes(nd.id))
@@ -203,11 +192,7 @@ export const utilBuildChatflow = async (req: Request, socketIO?: Server, isInter
for (const endingNode of endingNodes) {
const endingNodeData = endingNode.data
if (!endingNodeData) {
- return {
- executionError: true,
- status: 500,
- msg: `Ending node ${endingNode.id} data not found`
- }
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Ending node ${endingNode.id} data not found`)
}
const isEndingNode = endingNodeData?.outputs?.output === 'EndingNode'
@@ -219,11 +204,7 @@ export const utilBuildChatflow = async (req: Request, socketIO?: Server, isInter
endingNodeData.category !== 'Agents' &&
endingNodeData.category !== 'Engine'
) {
- return {
- executionError: true,
- status: 500,
- msg: `Ending node must be either a Chain or Agent`
- }
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Ending node must be either a Chain or Agent`)
}
if (
@@ -231,11 +212,10 @@ export const utilBuildChatflow = async (req: Request, socketIO?: Server, isInter
Object.keys(endingNodeData.outputs).length &&
!Object.values(endingNodeData.outputs ?? {}).includes(endingNodeData.name)
) {
- return {
- executionError: true,
- status: 500,
- msg: `Output of ${endingNodeData.label} (${endingNodeData.id}) must be ${endingNodeData.label}, can't be an Output Prediction`
- }
+ throw new ApiError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Output of ${endingNodeData.label} (${endingNodeData.id}) must be ${endingNodeData.label}, can't be an Output Prediction`
+ )
}
}
@@ -311,11 +291,7 @@ export const utilBuildChatflow = async (req: Request, socketIO?: Server, isInter
? reactFlowNodes.find((node: IReactFlowNode) => endingNodeIds[0] === node.id)
: reactFlowNodes[reactFlowNodes.length - 1]
if (!nodeToExecute) {
- return {
- executionError: true,
- status: 404,
- msg: `Node not found`
- }
+ throw new ApiError(StatusCodes.NOT_FOUND, `Node not found`)
}
if (incomingInput.overrideConfig) {
@@ -417,10 +393,6 @@ export const utilBuildChatflow = async (req: Request, socketIO?: Server, isInter
return result
} catch (e: any) {
logger.error('[server]: Error:', e)
- return {
- executionError: true,
- status: 500,
- msg: e.message
- }
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, e.message)
}
}
From 15a46da4c6004df94e59f15021939e2aa2a5b386 Mon Sep 17 00:00:00 2001
From: Octavian FlowiseAI <154992625+ocflowiseai@users.noreply.github.com>
Date: Thu, 4 Apr 2024 16:29:48 +0200
Subject: [PATCH 03/18] Update index.ts
---
.../server/src/services/credentials/index.ts | 30 +++++++------------
1 file changed, 10 insertions(+), 20 deletions(-)
diff --git a/packages/server/src/services/credentials/index.ts b/packages/server/src/services/credentials/index.ts
index 5c5d145ea4c..c8086b9a38e 100644
--- a/packages/server/src/services/credentials/index.ts
+++ b/packages/server/src/services/credentials/index.ts
@@ -3,6 +3,8 @@ import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
import { Credential } from '../../database/entities/Credential'
import { transformToCredentialEntity, decryptCredentialData } from '../../utils'
import { ICredentialReturnResponse } from '../../Interface'
+import { ApiError } from '../../errors/apiError'
+import { StatusCodes } from 'http-status-codes'
const createCredential = async (requestBody: any) => {
try {
@@ -12,7 +14,7 @@ const createCredential = async (requestBody: any) => {
const dbResponse = await appServer.AppDataSource.getRepository(Credential).save(credential)
return dbResponse
} catch (error) {
- throw new Error(`Error: credentialsService.createCredential - ${error}`)
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: credentialsService.createCredential - ${error}`)
}
}
@@ -22,15 +24,11 @@ const deleteCredentials = async (credentialId: string): Promise => {
const appServer = getRunningExpressApp()
const dbResponse = await appServer.AppDataSource.getRepository(Credential).delete({ id: credentialId })
if (!dbResponse) {
- return {
- executionError: true,
- status: 404,
- msg: `Credential ${credentialId} not found`
- }
+ throw new ApiError(StatusCodes.NOT_FOUND, `Credential ${credentialId} not found`)
}
return dbResponse
} catch (error) {
- throw new Error(`Error: credentialsService.deleteCredential - ${error}`)
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: credentialsService.deleteCredential - ${error}`)
}
}
@@ -61,7 +59,7 @@ const getAllCredentials = async (paramCredentialName: any) => {
}
return dbResponse
} catch (error) {
- throw new Error(`Error: credentialsService.getAllCredentials - ${error}`)
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: credentialsService.getAllCredentials - ${error}`)
}
}
@@ -72,11 +70,7 @@ const getCredentialById = async (credentialId: string): Promise => {
id: credentialId
})
if (!credential) {
- return {
- executionError: true,
- status: 404,
- msg: `Credential ${credentialId} not found`
- }
+ throw new ApiError(StatusCodes.NOT_FOUND, `Credential ${credentialId} not found`)
}
// Decrpyt credentialData
const decryptedCredentialData = await decryptCredentialData(
@@ -91,7 +85,7 @@ const getCredentialById = async (credentialId: string): Promise => {
const dbResponse = omit(returnCredential, ['encryptedData'])
return dbResponse
} catch (error) {
- throw new Error(`Error: credentialsService.createCredential - ${error}`)
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: credentialsService.createCredential - ${error}`)
}
}
@@ -102,18 +96,14 @@ const updateCredential = async (credentialId: string, requestBody: any): Promise
id: credentialId
})
if (!credential) {
- return {
- executionError: true,
- status: 404,
- msg: `Credential ${credentialId} not found`
- }
+ throw new ApiError(StatusCodes.NOT_FOUND, `Credential ${credentialId} not found`)
}
const updateCredential = await transformToCredentialEntity(requestBody)
await appServer.AppDataSource.getRepository(Credential).merge(credential, updateCredential)
const dbResponse = await appServer.AppDataSource.getRepository(Credential).save(credential)
return dbResponse
} catch (error) {
- throw new Error(`Error: credentialsService.updateCredential - ${error}`)
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: credentialsService.updateCredential - ${error}`)
}
}
From e0340bd2b3348a593cdeed9a8154e4311d483fa2 Mon Sep 17 00:00:00 2001
From: Octavian FlowiseAI <154992625+ocflowiseai@users.noreply.github.com>
Date: Thu, 4 Apr 2024 16:30:04 +0200
Subject: [PATCH 04/18] Update index.ts
---
.../src/services/openai-assistants/index.ts | 30 +++++--------------
1 file changed, 8 insertions(+), 22 deletions(-)
diff --git a/packages/server/src/services/openai-assistants/index.ts b/packages/server/src/services/openai-assistants/index.ts
index cffa2e3f1d6..96f822e920b 100644
--- a/packages/server/src/services/openai-assistants/index.ts
+++ b/packages/server/src/services/openai-assistants/index.ts
@@ -2,6 +2,8 @@ import OpenAI from 'openai'
import { decryptCredentialData } from '../../utils'
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
import { Credential } from '../../database/entities/Credential'
+import { ApiError } from '../../errors/apiError'
+import { StatusCodes } from 'http-status-codes'
// ----------------------------------------
// Assistants
@@ -15,28 +17,20 @@ const getAllOpenaiAssistants = async (credentialId: string): Promise => {
id: credentialId
})
if (!credential) {
- return {
- executionError: true,
- status: 404,
- msg: `Credential ${credentialId} not found in the database!`
- }
+ throw new ApiError(StatusCodes.NOT_FOUND, `Credential ${credentialId} not found in the database!`)
}
// Decrpyt credentialData
const decryptedCredentialData = await decryptCredentialData(credential.encryptedData)
const openAIApiKey = decryptedCredentialData['openAIApiKey']
if (!openAIApiKey) {
- return {
- executionError: true,
- status: 404,
- msg: `OpenAI ApiKey not found`
- }
+ throw new ApiError(StatusCodes.NOT_FOUND, `OpenAI ApiKey not found`)
}
const openai = new OpenAI({ apiKey: openAIApiKey })
const retrievedAssistants = await openai.beta.assistants.list()
const dbResponse = retrievedAssistants.data
return dbResponse
} catch (error) {
- throw new Error(`Error: openaiAssistantsService.getAllOpenaiAssistants - ${error}`)
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: openaiAssistantsService.getAllOpenaiAssistants - ${error}`)
}
}
@@ -48,21 +42,13 @@ const getSingleOpenaiAssistant = async (credentialId: string, assistantId: strin
id: credentialId
})
if (!credential) {
- return {
- executionError: true,
- status: 404,
- msg: `Credential ${credentialId} not found in the database!`
- }
+ throw new ApiError(StatusCodes.NOT_FOUND, `Credential ${credentialId} not found in the database!`)
}
// Decrpyt credentialData
const decryptedCredentialData = await decryptCredentialData(credential.encryptedData)
const openAIApiKey = decryptedCredentialData['openAIApiKey']
if (!openAIApiKey) {
- return {
- executionError: true,
- status: 404,
- msg: `OpenAI ApiKey not found`
- }
+ throw new ApiError(StatusCodes.NOT_FOUND, `OpenAI ApiKey not found`)
}
const openai = new OpenAI({ apiKey: openAIApiKey })
@@ -74,7 +60,7 @@ const getSingleOpenaiAssistant = async (credentialId: string, assistantId: strin
}
return dbResponse
} catch (error) {
- throw new Error(`Error: openaiAssistantsService.getSingleOpenaiAssistant - ${error}`)
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: openaiAssistantsService.getSingleOpenaiAssistant - ${error}`)
}
}
From 8b17019b30d16376d6a168f6433dfea1c13acfd9 Mon Sep 17 00:00:00 2001
From: Octavian FlowiseAI <154992625+ocflowiseai@users.noreply.github.com>
Date: Thu, 4 Apr 2024 16:30:16 +0200
Subject: [PATCH 05/18] Update index.ts
---
packages/server/src/services/tools/index.ts | 24 ++++++++-------------
1 file changed, 9 insertions(+), 15 deletions(-)
diff --git a/packages/server/src/services/tools/index.ts b/packages/server/src/services/tools/index.ts
index 42a579e1f22..886fb7778eb 100644
--- a/packages/server/src/services/tools/index.ts
+++ b/packages/server/src/services/tools/index.ts
@@ -1,6 +1,8 @@
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
import { Tool } from '../../database/entities/Tool'
import { getAppVersion } from '../../utils'
+import { ApiError } from '../../errors/apiError'
+import { StatusCodes } from 'http-status-codes'
const creatTool = async (requestBody: any): Promise => {
try {
@@ -16,7 +18,7 @@ const creatTool = async (requestBody: any): Promise => {
})
return dbResponse
} catch (error) {
- throw new Error(`Error: toolsService.creatTool - ${error}`)
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: toolsService.creatTool - ${error}`)
}
}
@@ -28,7 +30,7 @@ const deleteTool = async (toolId: string): Promise => {
})
return dbResponse
} catch (error) {
- throw new Error(`Error: toolsService.deleteTool - ${error}`)
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: toolsService.deleteTool - ${error}`)
}
}
@@ -38,7 +40,7 @@ const getAllTools = async (): Promise => {
const dbResponse = await appServer.AppDataSource.getRepository(Tool).find()
return dbResponse
} catch (error) {
- throw new Error(`Error: toolsService.getAllTools - ${error}`)
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: toolsService.getAllTools - ${error}`)
}
}
@@ -49,15 +51,11 @@ const getToolById = async (toolId: string): Promise => {
id: toolId
})
if (!dbResponse) {
- return {
- executionError: true,
- status: 404,
- msg: `Tool ${toolId} not found`
- }
+ throw new ApiError(StatusCodes.NOT_FOUND, `Tool ${toolId} not found`)
}
return dbResponse
} catch (error) {
- throw new Error(`Error: toolsService.getToolById - ${error}`)
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: toolsService.getToolById - ${error}`)
}
}
@@ -68,11 +66,7 @@ const updateTool = async (toolId: string, toolBody: any): Promise => {
id: toolId
})
if (!tool) {
- return {
- executionError: true,
- status: 404,
- msg: `Tool ${toolId} not found`
- }
+ throw new ApiError(StatusCodes.NOT_FOUND, `Tool ${toolId} not found`)
}
const updateTool = new Tool()
Object.assign(updateTool, toolBody)
@@ -80,7 +74,7 @@ const updateTool = async (toolId: string, toolBody: any): Promise => {
const dbResponse = await appServer.AppDataSource.getRepository(Tool).save(tool)
return dbResponse
} catch (error) {
- throw new Error(`Error: toolsService.getToolById - ${error}`)
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: toolsService.getToolById - ${error}`)
}
}
From 1d77ed087e451d779f3410d76a90c09afd22ceb4 Mon Sep 17 00:00:00 2001
From: Octavian FlowiseAI <154992625+ocflowiseai@users.noreply.github.com>
Date: Thu, 4 Apr 2024 16:30:36 +0200
Subject: [PATCH 06/18] Update index.ts
---
packages/server/src/services/versions/index.ts | 16 +++++-----------
1 file changed, 5 insertions(+), 11 deletions(-)
diff --git a/packages/server/src/services/versions/index.ts b/packages/server/src/services/versions/index.ts
index 391cdb1b84e..cbf5eba41e6 100644
--- a/packages/server/src/services/versions/index.ts
+++ b/packages/server/src/services/versions/index.ts
@@ -1,5 +1,7 @@
import path from 'path'
import * as fs from 'fs'
+import { ApiError } from '../../errors/apiError'
+import { StatusCodes } from 'http-status-codes'
const getVersion = async () => {
try {
@@ -20,11 +22,7 @@ const getVersion = async () => {
}
const packagejsonPath = getPackageJsonPath()
if (!packagejsonPath) {
- return {
- executionError: true,
- status: 404,
- msg: 'Version not found'
- }
+ throw new ApiError(StatusCodes.NOT_FOUND, `Version not found`)
}
try {
const content = await fs.promises.readFile(packagejsonPath, 'utf8')
@@ -33,14 +31,10 @@ const getVersion = async () => {
version: parsedContent.version
}
} catch (error) {
- return {
- executionError: true,
- status: 500,
- msg: `Version not found: ${error}`
- }
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Version not found: ${error}`)
}
} catch (error) {
- throw new Error(`Error: versionService.getVersion - ${error}`)
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: versionService.getVersion - ${error}`)
}
}
From 1f74117219b1250a76d9278a94dbd1ca8a68a040 Mon Sep 17 00:00:00 2001
From: Octavian FlowiseAI <154992625+ocflowiseai@users.noreply.github.com>
Date: Thu, 4 Apr 2024 16:34:40 +0200
Subject: [PATCH 07/18] Update index.ts
---
packages/server/src/services/fetch-links/index.ts | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/packages/server/src/services/fetch-links/index.ts b/packages/server/src/services/fetch-links/index.ts
index 58247d72f40..dcf09a4b15e 100644
--- a/packages/server/src/services/fetch-links/index.ts
+++ b/packages/server/src/services/fetch-links/index.ts
@@ -1,14 +1,12 @@
import { webCrawl, xmlScrape } from 'flowise-components'
+import { ApiError } from '../../errors/apiError'
+import { StatusCodes } from 'http-status-codes'
const getAllLinks = async (requestUrl: string, relativeLinksMethod: string, queryLimit: string): Promise => {
try {
const url = decodeURIComponent(requestUrl)
if (!relativeLinksMethod) {
- return {
- executionError: true,
- status: 500,
- msg: `Please choose a Relative Links Method in Additional Parameters!`
- }
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Please choose a Relative Links Method in Additional Parameters!`)
}
const limit = parseInt(queryLimit)
if (process.env.DEBUG === 'true') console.info(`Start ${relativeLinksMethod}`)
@@ -20,7 +18,7 @@ const getAllLinks = async (requestUrl: string, relativeLinksMethod: string, quer
}
return dbResponse
} catch (error) {
- throw new Error(`Error: fetchLinksService.getAllLinks - ${error}`)
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: fetchLinksService.getAllLinks - ${error}`)
}
}
From a7832ef91c9419e22c39c92be8df6803c455d5b2 Mon Sep 17 00:00:00 2001
From: Octavian FlowiseAI <154992625+ocflowiseai@users.noreply.github.com>
Date: Thu, 4 Apr 2024 16:45:55 +0200
Subject: [PATCH 08/18] Update index.ts
---
packages/server/src/services/nodes/index.ts | 38 ++++++++-------------
1 file changed, 14 insertions(+), 24 deletions(-)
diff --git a/packages/server/src/services/nodes/index.ts b/packages/server/src/services/nodes/index.ts
index 0bf097b491a..4993f3b788e 100644
--- a/packages/server/src/services/nodes/index.ts
+++ b/packages/server/src/services/nodes/index.ts
@@ -4,6 +4,8 @@ import { INodeData } from '../../Interface'
import { INodeOptionsValue, ICommonObject, handleEscapeCharacters } from 'flowise-components'
import { databaseEntities } from '../../utils'
import logger from '../../utils/logger'
+import { ApiError } from '../../errors/apiError'
+import { StatusCodes } from 'http-status-codes'
// Get all component nodes
const getAllNodes = async () => {
@@ -16,7 +18,7 @@ const getAllNodes = async () => {
}
return dbResponse
} catch (error) {
- throw new Error(`Error: nodesService.getAllNodes - ${error}`)
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: nodesService.getAllNodes - ${error}`)
}
}
@@ -28,10 +30,10 @@ const getNodeByName = async (nodeName: string) => {
const dbResponse = appServer.nodesPool.componentNodes[nodeName]
return dbResponse
} else {
- throw new Error(`Node ${nodeName} not found`)
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Node ${nodeName} not found`)
}
} catch (error) {
- throw new Error(`Error: nodesService.getAllNodes - ${error}`)
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: nodesService.getAllNodes - ${error}`)
}
}
@@ -42,20 +44,20 @@ const getSingleNodeIcon = async (nodeName: string) => {
if (Object.prototype.hasOwnProperty.call(appServer.nodesPool.componentNodes, nodeName)) {
const nodeInstance = appServer.nodesPool.componentNodes[nodeName]
if (nodeInstance.icon === undefined) {
- throw new Error(`Node ${nodeName} icon not found`)
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Node ${nodeName} icon not found`)
}
if (nodeInstance.icon.endsWith('.svg') || nodeInstance.icon.endsWith('.png') || nodeInstance.icon.endsWith('.jpg')) {
const filepath = nodeInstance.icon
return filepath
} else {
- throw new Error(`Node ${nodeName} icon is missing icon`)
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Node ${nodeName} icon is missing icon`)
}
} else {
- throw new Error(`Node ${nodeName} not found`)
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Node ${nodeName} not found`)
}
} catch (error) {
- throw new Error(`Error: nodesService.getSingleNodeIcon - ${error}`)
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: nodesService.getSingleNodeIcon - ${error}`)
}
}
@@ -78,14 +80,10 @@ const getSingleNodeAsyncOptions = async (nodeName: string, requestBody: any): Pr
return []
}
} else {
- return {
- executionError: true,
- status: 404,
- msg: `Node ${nodeName} not found`
- }
+ throw new ApiError(StatusCodes.NOT_FOUND, `Node ${nodeName} not found`)
}
} catch (error) {
- throw new Error(`Error: nodesService.getSingleNodeAsyncOptions - ${error}`)
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: nodesService.getSingleNodeAsyncOptions - ${error}`)
}
}
@@ -115,21 +113,13 @@ const executeCustomFunction = async (requestBody: any) => {
return dbResponse
} catch (error) {
- return {
- executionError: true,
- status: 500,
- msg: `Error running custom function: ${error}`
- }
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error running custom function: ${error}`)
}
} else {
- return {
- executionError: true,
- status: 404,
- msg: `Node customFunction not found`
- }
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Node customFunction not found`)
}
} catch (error) {
- throw new Error(`Error: nodesService.executeCustomFunction - ${error}`)
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: nodesService.executeCustomFunction - ${error}`)
}
}
From e4a8716986eb2c95081f46cc28f06cc321def9b7 Mon Sep 17 00:00:00 2001
From: Octavian FlowiseAI <154992625+ocflowiseai@users.noreply.github.com>
Date: Thu, 4 Apr 2024 17:11:09 +0200
Subject: [PATCH 09/18] Update index.ts
---
.../server/src/services/assistants/index.ts | 90 +++++--------------
1 file changed, 20 insertions(+), 70 deletions(-)
diff --git a/packages/server/src/services/assistants/index.ts b/packages/server/src/services/assistants/index.ts
index 8b5a431f3ce..afad64ce961 100644
--- a/packages/server/src/services/assistants/index.ts
+++ b/packages/server/src/services/assistants/index.ts
@@ -6,16 +6,14 @@ import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
import { Assistant } from '../../database/entities/Assistant'
import { Credential } from '../../database/entities/Credential'
import { getUserHome, decryptCredentialData, getAppVersion } from '../../utils'
+import { ApiError } from '../../errors/apiError'
+import { StatusCodes } from 'http-status-codes'
const creatAssistant = async (requestBody: any): Promise => {
try {
const appServer = getRunningExpressApp()
if (!requestBody.details) {
- return {
- executionError: true,
- status: 500,
- msg: `Invalid request body`
- }
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Invalid request body`)
}
const assistantDetails = JSON.parse(requestBody.details)
try {
@@ -24,22 +22,14 @@ const creatAssistant = async (requestBody: any): Promise => {
})
if (!credential) {
- return {
- executionError: true,
- status: 404,
- msg: `Credential ${requestBody.credential} not found`
- }
+ throw new ApiError(StatusCodes.NOT_FOUND, `Credential ${requestBody.credential} not found`)
}
// Decrpyt credentialData
const decryptedCredentialData = await decryptCredentialData(credential.encryptedData)
const openAIApiKey = decryptedCredentialData['openAIApiKey']
if (!openAIApiKey) {
- return {
- executionError: true,
- status: 404,
- msg: `OpenAI ApiKey not found`
- }
+ throw new ApiError(StatusCodes.NOT_FOUND, `OpenAI ApiKey not found`)
}
const openai = new OpenAI({ apiKey: openAIApiKey })
@@ -121,11 +111,7 @@ const creatAssistant = async (requestBody: any): Promise => {
requestBody.details = JSON.stringify(newAssistantDetails)
} catch (error) {
- return {
- executionError: true,
- status: 500,
- msg: `Error creating new assistant: ${error}`
- }
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error creating new assistant: ${error}`)
}
const newAssistant = new Assistant()
Object.assign(newAssistant, requestBody)
@@ -139,7 +125,7 @@ const creatAssistant = async (requestBody: any): Promise => {
})
return dbResponse
} catch (error) {
- throw new Error(`Error: assistantsService.creatTool - ${error}`)
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: assistantsService.creatTool - ${error}`)
}
}
@@ -150,11 +136,7 @@ const deleteAssistant = async (assistantId: string, isDeleteBoth: any): Promise<
id: assistantId
})
if (!assistant) {
- return {
- executionError: true,
- status: 404,
- msg: `Assistant ${assistantId} not found`
- }
+ throw new ApiError(StatusCodes.NOT_FOUND, `Assistant ${assistantId} not found`)
}
try {
const assistantDetails = JSON.parse(assistant.details)
@@ -163,22 +145,14 @@ const deleteAssistant = async (assistantId: string, isDeleteBoth: any): Promise<
})
if (!credential) {
- return {
- executionError: true,
- status: 404,
- msg: `Credential ${assistant.credential} not found`
- }
+ throw new ApiError(StatusCodes.NOT_FOUND, `Credential ${assistant.credential} not found`)
}
// Decrpyt credentialData
const decryptedCredentialData = await decryptCredentialData(credential.encryptedData)
const openAIApiKey = decryptedCredentialData['openAIApiKey']
if (!openAIApiKey) {
- return {
- executionError: true,
- status: 404,
- msg: `OpenAI ApiKey not found`
- }
+ throw new ApiError(StatusCodes.NOT_FOUND, `OpenAI ApiKey not found`)
}
const openai = new OpenAI({ apiKey: openAIApiKey })
@@ -189,15 +163,11 @@ const deleteAssistant = async (assistantId: string, isDeleteBoth: any): Promise<
if (error.status === 404 && error.type === 'invalid_request_error') {
return 'OK'
} else {
- return {
- executionError: true,
- status: 500,
- msg: `Error deleting assistant: ${error}`
- }
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error deleting assistant: ${error}`)
}
}
} catch (error) {
- throw new Error(`Error: assistantsService.deleteTool - ${error}`)
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: assistantsService.deleteTool - ${error}`)
}
}
@@ -207,7 +177,7 @@ const getAllAssistants = async (): Promise => {
const dbResponse = await appServer.AppDataSource.getRepository(Assistant).find()
return dbResponse
} catch (error) {
- throw new Error(`Error: assistantsService.getAllAssistants - ${error}`)
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: assistantsService.getAllAssistants - ${error}`)
}
}
@@ -218,15 +188,11 @@ const getAssistantById = async (assistantId: string): Promise => {
id: assistantId
})
if (!dbResponse) {
- return {
- executionError: true,
- status: 404,
- msg: `Assistant ${assistantId} not found`
- }
+ throw new ApiError(StatusCodes.NOT_FOUND, `Assistant ${assistantId} not found`)
}
return dbResponse
} catch (error) {
- throw new Error(`Error: assistantsService.getAssistantById - ${error}`)
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: assistantsService.getAssistantById - ${error}`)
}
}
@@ -238,11 +204,7 @@ const updateAssistant = async (assistantId: string, requestBody: any): Promise
Date: Thu, 4 Apr 2024 17:12:06 +0200
Subject: [PATCH 10/18] Update index.ts
---
packages/server/src/services/flow-configs/index.ts | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/packages/server/src/services/flow-configs/index.ts b/packages/server/src/services/flow-configs/index.ts
index 8dbcd6d3fae..35c8494b407 100644
--- a/packages/server/src/services/flow-configs/index.ts
+++ b/packages/server/src/services/flow-configs/index.ts
@@ -2,17 +2,15 @@ import { findAvailableConfigs } from '../../utils'
import { IReactFlowObject } from '../../Interface'
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
import chatflowsService from '../chatflows'
+import { ApiError } from '../../errors/apiError'
+import { StatusCodes } from 'http-status-codes'
const getSingleFlowConfig = async (chatflowId: string): Promise => {
try {
const appServer = getRunningExpressApp()
const chatflow = await chatflowsService.getChatflowById(chatflowId)
if (!chatflow) {
- return {
- executionError: true,
- status: 404,
- msg: `Chatflow ${chatflowId} not found in the database!`
- }
+ throw new ApiError(StatusCodes.NOT_FOUND, `Chatflow ${chatflowId} not found in the database!`)
}
const flowData = chatflow.flowData
const parsedFlowData: IReactFlowObject = JSON.parse(flowData)
@@ -20,7 +18,7 @@ const getSingleFlowConfig = async (chatflowId: string): Promise => {
const dbResponse = findAvailableConfigs(nodes, appServer.nodesPool.componentCredentials)
return dbResponse
} catch (error) {
- throw new Error(`Error: flowConfigService.getSingleFlowConfig - ${error}`)
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: flowConfigService.getSingleFlowConfig - ${error}`)
}
}
From f23022a9dfb0ea9f7a058f2067607dc4e0677cca Mon Sep 17 00:00:00 2001
From: Octavian FlowiseAI <154992625+ocflowiseai@users.noreply.github.com>
Date: Thu, 4 Apr 2024 17:38:38 +0200
Subject: [PATCH 11/18] Consistency
---
.../server/src/controllers/apikey/index.ts | 3 ---
.../src/controllers/assistants/index.ts | 19 ++++---------------
.../src/controllers/chat-messages/index.ts | 9 ---------
.../server/src/controllers/chatflows/index.ts | 18 ------------------
.../src/controllers/credentials/index.ts | 9 ---------
.../src/controllers/fetch-links/index.ts | 3 ---
.../src/controllers/flow-configs/index.ts | 3 ---
.../src/controllers/load-prompts/index.ts | 3 ---
.../server/src/controllers/nodes/index.ts | 6 ------
.../controllers/openai-assistants/index.ts | 6 ------
.../src/controllers/predictions/index.ts | 19 +++++++++----------
.../server/src/controllers/stats/index.ts | 3 ---
.../server/src/controllers/tools/index.ts | 15 ---------------
.../server/src/controllers/versions/index.ts | 3 ---
packages/server/src/services/apikey/index.ts | 8 +++-----
.../server/src/services/predictions/index.ts | 18 ++++++++++++++++++
.../ui/src/views/chatmessage/ChatMessage.jsx | 4 ----
17 files changed, 34 insertions(+), 115 deletions(-)
create mode 100644 packages/server/src/services/predictions/index.ts
diff --git a/packages/server/src/controllers/apikey/index.ts b/packages/server/src/controllers/apikey/index.ts
index c35a69f8b7a..3e88f95bb65 100644
--- a/packages/server/src/controllers/apikey/index.ts
+++ b/packages/server/src/controllers/apikey/index.ts
@@ -61,9 +61,6 @@ const verifyApiKey = async (req: Request, res: Response, next: NextFunction) =>
new ApiError(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)
diff --git a/packages/server/src/controllers/assistants/index.ts b/packages/server/src/controllers/assistants/index.ts
index eed007520eb..e6d97570936 100644
--- a/packages/server/src/controllers/assistants/index.ts
+++ b/packages/server/src/controllers/assistants/index.ts
@@ -7,9 +7,6 @@ const creatAssistant = async (req: Request, res: Response, next: NextFunction) =
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)
- }
return res.json(apiResponse)
} catch (error) {
next(error)
@@ -22,9 +19,7 @@ const deleteAssistant = async (req: Request, res: Response, next: NextFunction)
throw new Error(`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 +29,7 @@ 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)
@@ -49,9 +42,7 @@ const getAssistantById = async (req: Request, res: Response, next: NextFunction)
throw new Error(`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)
@@ -67,9 +58,7 @@ const updateAssistant = async (req: Request, res: Response, next: NextFunction)
throw new Error(`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)
diff --git a/packages/server/src/controllers/chat-messages/index.ts b/packages/server/src/controllers/chat-messages/index.ts
index 02562b3a62d..cb0e26f2fb4 100644
--- a/packages/server/src/controllers/chat-messages/index.ts
+++ b/packages/server/src/controllers/chat-messages/index.ts
@@ -59,9 +59,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 +87,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)
@@ -139,9 +133,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)
diff --git a/packages/server/src/controllers/chatflows/index.ts b/packages/server/src/controllers/chatflows/index.ts
index b3c6bd50ee1..e764e570f96 100644
--- a/packages/server/src/controllers/chatflows/index.ts
+++ b/packages/server/src/controllers/chatflows/index.ts
@@ -10,9 +10,6 @@ const checkIfChatflowIsValidForStreaming = async (req: Request, res: Response, n
throw new Error(`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)
@@ -25,9 +22,6 @@ const checkIfChatflowIsValidForUploads = async (req: Request, res: Response, nex
throw new Error(`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)
@@ -66,9 +60,6 @@ const getChatflowByApiKey = async (req: Request, res: Response, next: NextFuncti
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)
@@ -81,9 +72,6 @@ const getChatflowById = async (req: Request, res: Response, next: NextFunction)
throw new Error(`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)
@@ -132,9 +120,6 @@ const getSinglePublicChatflow = async (req: Request, res: Response, next: NextFu
throw new Error(`Error: chatflowsRouter.updateChatflow - 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)
@@ -147,9 +132,6 @@ const getSinglePublicChatbotConfig = async (req: Request, res: Response, next: N
throw new Error(`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)
diff --git a/packages/server/src/controllers/credentials/index.ts b/packages/server/src/controllers/credentials/index.ts
index 2bc599a2f10..0dea25095a8 100644
--- a/packages/server/src/controllers/credentials/index.ts
+++ b/packages/server/src/controllers/credentials/index.ts
@@ -19,9 +19,6 @@ const deleteCredentials = async (req: Request, res: Response, next: NextFunction
throw new Error(`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)
@@ -43,9 +40,6 @@ const getCredentialById = async (req: Request, res: Response, next: NextFunction
throw new Error(`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)
@@ -61,9 +55,6 @@ const updateCredential = async (req: Request, res: Response, next: NextFunction)
throw new Error(`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)
diff --git a/packages/server/src/controllers/fetch-links/index.ts b/packages/server/src/controllers/fetch-links/index.ts
index 586f1159e1b..7f32d690e59 100644
--- a/packages/server/src/controllers/fetch-links/index.ts
+++ b/packages/server/src/controllers/fetch-links/index.ts
@@ -17,9 +17,6 @@ const getAllLinks = async (req: Request, res: Response, next: NextFunction) => {
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)
diff --git a/packages/server/src/controllers/flow-configs/index.ts b/packages/server/src/controllers/flow-configs/index.ts
index ce576497609..fba673d2cbf 100644
--- a/packages/server/src/controllers/flow-configs/index.ts
+++ b/packages/server/src/controllers/flow-configs/index.ts
@@ -7,9 +7,6 @@ const getSingleFlowConfig = async (req: Request, res: Response, next: NextFuncti
throw new Error(`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)
diff --git a/packages/server/src/controllers/load-prompts/index.ts b/packages/server/src/controllers/load-prompts/index.ts
index 6fa38aef66f..c428aa6faf0 100644
--- a/packages/server/src/controllers/load-prompts/index.ts
+++ b/packages/server/src/controllers/load-prompts/index.ts
@@ -7,9 +7,6 @@ const createPrompt = async (req: Request, res: Response, next: NextFunction) =>
throw new Error(`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)
diff --git a/packages/server/src/controllers/nodes/index.ts b/packages/server/src/controllers/nodes/index.ts
index ac448d933e1..efd5a68e82b 100644
--- a/packages/server/src/controllers/nodes/index.ts
+++ b/packages/server/src/controllers/nodes/index.ts
@@ -43,9 +43,6 @@ const getSingleNodeAsyncOptions = async (req: Request, res: Response, next: Next
throw new Error(`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)
@@ -58,9 +55,6 @@ const executeCustomFunction = async (req: Request, res: Response, next: NextFunc
throw new Error(`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)
diff --git a/packages/server/src/controllers/openai-assistants/index.ts b/packages/server/src/controllers/openai-assistants/index.ts
index 539f2fbf691..e411b0b389b 100644
--- a/packages/server/src/controllers/openai-assistants/index.ts
+++ b/packages/server/src/controllers/openai-assistants/index.ts
@@ -12,9 +12,6 @@ const getAllOpenaiAssistants = async (req: Request, res: Response, next: NextFun
throw new Error(`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)
@@ -31,9 +28,6 @@ const getSingleOpenaiAssistant = async (req: Request, res: Response, next: NextF
throw new Error(`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)
diff --git a/packages/server/src/controllers/predictions/index.ts b/packages/server/src/controllers/predictions/index.ts
index 936bfe1ccab..1ec6e6215a8 100644
--- a/packages/server/src/controllers/predictions/index.ts
+++ b/packages/server/src/controllers/predictions/index.ts
@@ -2,20 +2,22 @@ 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 { ApiError } from '../../errors/apiError'
+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!`)
+ throw new ApiError(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!`)
+ throw new ApiError(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 ApiError(StatusCodes.NOT_FOUND, `Chatflow ${req.params.id} not found`)
}
let isDomainAllowed = true
logger.info(`[server]: Request originated from ${req.headers.origin}`)
@@ -37,15 +39,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 ApiError(StatusCodes.UNAUTHORIZED, `This site is not allowed to access this chatbot`)
}
} catch (error) {
next(error)
diff --git a/packages/server/src/controllers/stats/index.ts b/packages/server/src/controllers/stats/index.ts
index e1c97c490c3..fc60d66efa6 100644
--- a/packages/server/src/controllers/stats/index.ts
+++ b/packages/server/src/controllers/stats/index.ts
@@ -26,9 +26,6 @@ const getChatflowStats = async (req: Request, res: Response, next: NextFunction)
}
}
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)
diff --git a/packages/server/src/controllers/tools/index.ts b/packages/server/src/controllers/tools/index.ts
index 196032f66e0..f1376795a20 100644
--- a/packages/server/src/controllers/tools/index.ts
+++ b/packages/server/src/controllers/tools/index.ts
@@ -7,9 +7,6 @@ const creatTool = async (req: Request, res: Response, next: NextFunction) => {
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)
- }
return res.json(apiResponse)
} catch (error) {
next(error)
@@ -22,9 +19,6 @@ const deleteTool = async (req: Request, res: Response, next: NextFunction) => {
throw new Error(`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 +28,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)
@@ -49,9 +40,6 @@ const getToolById = async (req: Request, res: Response, next: NextFunction) => {
throw new Error(`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)
@@ -67,9 +55,6 @@ const updateTool = async (req: Request, res: Response, next: NextFunction) => {
throw new Error(`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)
diff --git a/packages/server/src/controllers/versions/index.ts b/packages/server/src/controllers/versions/index.ts
index 7a6f76c461b..26697620aab 100644
--- a/packages/server/src/controllers/versions/index.ts
+++ b/packages/server/src/controllers/versions/index.ts
@@ -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)
diff --git a/packages/server/src/services/apikey/index.ts b/packages/server/src/services/apikey/index.ts
index 5a1bc3344c8..0e0ae624599 100644
--- a/packages/server/src/services/apikey/index.ts
+++ b/packages/server/src/services/apikey/index.ts
@@ -1,6 +1,8 @@
import { addAPIKey, deleteAPIKey, getAPIKeys, updateAPIKey } from '../../utils/apiKey'
import { addChatflowsCount } from '../../utils/addChatflowsCount'
import { getApiKey } from '../../utils/apiKey'
+import { ApiError } from '../../errors/apiError'
+import { StatusCodes } from 'http-status-codes'
const getAllApiKeys = async () => {
try {
@@ -47,11 +49,7 @@ const verifyApiKey = async (paramApiKey: string): Promise => {
try {
const apiKey = await getApiKey(paramApiKey)
if (!apiKey) {
- return {
- executionError: true,
- status: 401,
- msg: `Unauthorized`
- }
+ throw new ApiError(StatusCodes.UNAUTHORIZED, `Unauthorized`)
}
const dbResponse = 'OK'
return dbResponse
diff --git a/packages/server/src/services/predictions/index.ts b/packages/server/src/services/predictions/index.ts
new file mode 100644
index 00000000000..c00374679ab
--- /dev/null
+++ b/packages/server/src/services/predictions/index.ts
@@ -0,0 +1,18 @@
+import { StatusCodes } from 'http-status-codes'
+import { utilBuildChatflow } from '../../utils/buildChatflow'
+import { Server } from 'socket.io'
+import { ApiError } from '../../errors/apiError'
+import { Request } from 'express'
+
+const buildChatflow = async (fullRequest: Request, ioServer: Server) => {
+ try {
+ const dbResponse = await utilBuildChatflow(fullRequest, ioServer)
+ return dbResponse
+ } catch (error) {
+ throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, 'Error: predictionsServices.buildChatflow failed!')
+ }
+}
+
+export default {
+ buildChatflow
+}
diff --git a/packages/ui/src/views/chatmessage/ChatMessage.jsx b/packages/ui/src/views/chatmessage/ChatMessage.jsx
index 2cd641e401e..8626ff13c66 100644
--- a/packages/ui/src/views/chatmessage/ChatMessage.jsx
+++ b/packages/ui/src/views/chatmessage/ChatMessage.jsx
@@ -406,10 +406,6 @@ export const ChatMessage = ({ open, chatflowid, isDialog, previews, setPreviews
if (response.data) {
const data = response.data
- if (data.executionError) {
- handleError(data.msg)
- return
- }
setMessages((prevMessages) => {
let allMessages = [...cloneDeep(prevMessages)]
From 943ce289c190b2b98ae688b7e43f7e1819fa5119 Mon Sep 17 00:00:00 2001
From: ocflowiseai <154992625+ocflowiseai@users.noreply.github.com>
Date: Mon, 8 Apr 2024 03:58:51 +0200
Subject: [PATCH 12/18] Rename ApiError to InternalServerError
---
.../server/src/controllers/apikey/index.ts | 12 ++---
.../src/controllers/predictions/index.ts | 16 +++++--
.../index.ts | 2 +-
.../server/src/middlewares/errors/index.ts | 4 +-
packages/server/src/services/apikey/index.ts | 4 +-
.../server/src/services/assistants/index.ts | 38 +++++++--------
.../server/src/services/chatflows/index.ts | 48 +++++++++++--------
.../server/src/services/credentials/index.ts | 18 +++----
.../server/src/services/fetch-links/index.ts | 9 ++--
.../server/src/services/flow-configs/index.ts | 6 +--
packages/server/src/services/nodes/index.ts | 26 +++++-----
.../src/services/openai-assistants/index.ts | 17 ++++---
.../server/src/services/predictions/index.ts | 4 +-
packages/server/src/services/tools/index.ts | 16 +++----
.../server/src/services/versions/index.ts | 8 ++--
packages/server/src/utils/buildChatflow.ts | 18 +++----
16 files changed, 132 insertions(+), 114 deletions(-)
rename packages/server/src/errors/{apiError => internalServerError}/index.ts (85%)
diff --git a/packages/server/src/controllers/apikey/index.ts b/packages/server/src/controllers/apikey/index.ts
index 3e88f95bb65..b465cb6653e 100644
--- a/packages/server/src/controllers/apikey/index.ts
+++ b/packages/server/src/controllers/apikey/index.ts
@@ -1,6 +1,6 @@
import { Request, Response, NextFunction } from 'express'
import { StatusCodes } from 'http-status-codes'
-import { ApiError } from '../../errors/apiError'
+import { InternalServerError } from '../../errors/internalServerError'
import apikeyService from '../../services/apikey'
// Get api keys
@@ -16,7 +16,7 @@ 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!`)
+ throw new InternalServerError(StatusCodes.PRECONDITION_FAILED, `Error: apikeyController.createApiKey - keyName not provided!`)
}
const apiResponse = await apikeyService.createApiKey(req.body.keyName)
return res.json(apiResponse)
@@ -29,10 +29,10 @@ const createApiKey = async (req: Request, res: Response, next: NextFunction) =>
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!`)
+ throw new InternalServerError(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!`)
+ throw new InternalServerError(StatusCodes.PRECONDITION_FAILED, `Error: apikeyController.updateApiKey - keyName not provided!`)
}
const apiResponse = await apikeyService.updateApiKey(req.params.id, req.body.keyName)
return res.json(apiResponse)
@@ -45,7 +45,7 @@ const updateApiKey = async (req: Request, res: Response, next: NextFunction) =>
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!`)
+ throw new InternalServerError(StatusCodes.PRECONDITION_FAILED, `Error: apikeyController.deleteApiKey - id not provided!`)
}
const apiResponse = await apikeyService.deleteApiKey(req.params.id)
return res.json(apiResponse)
@@ -58,7 +58,7 @@ const deleteApiKey = async (req: Request, res: Response, next: NextFunction) =>
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!`)
+ throw new InternalServerError(StatusCodes.PRECONDITION_FAILED, `Error: apikeyController.verifyApiKey - apiKey not provided!`)
}
const apiResponse = await apikeyService.verifyApiKey(req.params.apiKey)
return res.json(apiResponse)
diff --git a/packages/server/src/controllers/predictions/index.ts b/packages/server/src/controllers/predictions/index.ts
index 1ec6e6215a8..eea642e68cb 100644
--- a/packages/server/src/controllers/predictions/index.ts
+++ b/packages/server/src/controllers/predictions/index.ts
@@ -3,21 +3,27 @@ import { getRateLimiter } from '../../utils/rateLimit'
import chatflowsService from '../../services/chatflows'
import logger from '../../utils/logger'
import predictionsServices from '../../services/predictions'
-import { ApiError } from '../../errors/apiError'
+import { InternalServerError } from '../../errors/internalServerError'
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 ApiError(StatusCodes.PRECONDITION_FAILED, `Error: predictionsController.createPrediction - id not provided!`)
+ throw new InternalServerError(
+ StatusCodes.PRECONDITION_FAILED,
+ `Error: predictionsController.createPrediction - id not provided!`
+ )
}
if (typeof req.body === 'undefined' || req.body === '') {
- throw new ApiError(StatusCodes.PRECONDITION_FAILED, `Error: predictionsController.createPrediction - body not provided!`)
+ throw new InternalServerError(
+ StatusCodes.PRECONDITION_FAILED,
+ `Error: predictionsController.createPrediction - body not provided!`
+ )
}
const chatflow = await chatflowsService.getChatflowById(req.params.id)
if (!chatflow) {
- throw new ApiError(StatusCodes.NOT_FOUND, `Chatflow ${req.params.id} not found`)
+ throw new InternalServerError(StatusCodes.NOT_FOUND, `Chatflow ${req.params.id} not found`)
}
let isDomainAllowed = true
logger.info(`[server]: Request originated from ${req.headers.origin}`)
@@ -44,7 +50,7 @@ const createPrediction = async (req: Request, res: Response, next: NextFunction)
const apiResponse = await predictionsServices.buildChatflow(req, req?.io)
return res.json(apiResponse)
} else {
- throw new ApiError(StatusCodes.UNAUTHORIZED, `This site is not allowed to access this chatbot`)
+ throw new InternalServerError(StatusCodes.UNAUTHORIZED, `This site is not allowed to access this chatbot`)
}
} catch (error) {
next(error)
diff --git a/packages/server/src/errors/apiError/index.ts b/packages/server/src/errors/internalServerError/index.ts
similarity index 85%
rename from packages/server/src/errors/apiError/index.ts
rename to packages/server/src/errors/internalServerError/index.ts
index 641e2d5a128..0b37eff5b1c 100644
--- a/packages/server/src/errors/apiError/index.ts
+++ b/packages/server/src/errors/internalServerError/index.ts
@@ -1,4 +1,4 @@
-export class ApiError extends Error {
+export class InternalServerError extends Error {
statusCode: number
constructor(statusCode: number, message: string) {
super(message)
diff --git a/packages/server/src/middlewares/errors/index.ts b/packages/server/src/middlewares/errors/index.ts
index 3e97daf6dfc..1a00f14b441 100644
--- a/packages/server/src/middlewares/errors/index.ts
+++ b/packages/server/src/middlewares/errors/index.ts
@@ -1,10 +1,10 @@
import { NextFunction, Request, Response } from 'express'
import { StatusCodes } from 'http-status-codes'
-import { ApiError } from '../../errors/apiError'
+import { InternalServerError } from '../../errors/internalServerError'
// we need eslint because we have to pass next arg for the error middleware
// eslint-disable-next-line
-async function errorHandlerMiddleware(err: ApiError, req: Request, res: Response, next: NextFunction) {
+async function errorHandlerMiddleware(err: InternalServerError, req: Request, res: Response, next: NextFunction) {
let displayedError = {
statusCode: err.statusCode || StatusCodes.INTERNAL_SERVER_ERROR,
success: false,
diff --git a/packages/server/src/services/apikey/index.ts b/packages/server/src/services/apikey/index.ts
index 0e0ae624599..86de1eef223 100644
--- a/packages/server/src/services/apikey/index.ts
+++ b/packages/server/src/services/apikey/index.ts
@@ -1,7 +1,7 @@
import { addAPIKey, deleteAPIKey, getAPIKeys, updateAPIKey } from '../../utils/apiKey'
import { addChatflowsCount } from '../../utils/addChatflowsCount'
import { getApiKey } from '../../utils/apiKey'
-import { ApiError } from '../../errors/apiError'
+import { InternalServerError } from '../../errors/internalServerError'
import { StatusCodes } from 'http-status-codes'
const getAllApiKeys = async () => {
@@ -49,7 +49,7 @@ const verifyApiKey = async (paramApiKey: string): Promise => {
try {
const apiKey = await getApiKey(paramApiKey)
if (!apiKey) {
- throw new ApiError(StatusCodes.UNAUTHORIZED, `Unauthorized`)
+ throw new InternalServerError(StatusCodes.UNAUTHORIZED, `Unauthorized`)
}
const dbResponse = 'OK'
return dbResponse
diff --git a/packages/server/src/services/assistants/index.ts b/packages/server/src/services/assistants/index.ts
index afad64ce961..25259ead777 100644
--- a/packages/server/src/services/assistants/index.ts
+++ b/packages/server/src/services/assistants/index.ts
@@ -6,14 +6,14 @@ import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
import { Assistant } from '../../database/entities/Assistant'
import { Credential } from '../../database/entities/Credential'
import { getUserHome, decryptCredentialData, getAppVersion } from '../../utils'
-import { ApiError } from '../../errors/apiError'
+import { InternalServerError } from '../../errors/internalServerError'
import { StatusCodes } from 'http-status-codes'
const creatAssistant = async (requestBody: any): Promise => {
try {
const appServer = getRunningExpressApp()
if (!requestBody.details) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Invalid request body`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Invalid request body`)
}
const assistantDetails = JSON.parse(requestBody.details)
try {
@@ -22,14 +22,14 @@ const creatAssistant = async (requestBody: any): Promise => {
})
if (!credential) {
- throw new ApiError(StatusCodes.NOT_FOUND, `Credential ${requestBody.credential} not found`)
+ throw new InternalServerError(StatusCodes.NOT_FOUND, `Credential ${requestBody.credential} not found`)
}
// Decrpyt credentialData
const decryptedCredentialData = await decryptCredentialData(credential.encryptedData)
const openAIApiKey = decryptedCredentialData['openAIApiKey']
if (!openAIApiKey) {
- throw new ApiError(StatusCodes.NOT_FOUND, `OpenAI ApiKey not found`)
+ throw new InternalServerError(StatusCodes.NOT_FOUND, `OpenAI ApiKey not found`)
}
const openai = new OpenAI({ apiKey: openAIApiKey })
@@ -111,7 +111,7 @@ const creatAssistant = async (requestBody: any): Promise => {
requestBody.details = JSON.stringify(newAssistantDetails)
} catch (error) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error creating new assistant: ${error}`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error creating new assistant: ${error}`)
}
const newAssistant = new Assistant()
Object.assign(newAssistant, requestBody)
@@ -125,7 +125,7 @@ const creatAssistant = async (requestBody: any): Promise => {
})
return dbResponse
} catch (error) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: assistantsService.creatTool - ${error}`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: assistantsService.creatTool - ${error}`)
}
}
@@ -136,7 +136,7 @@ const deleteAssistant = async (assistantId: string, isDeleteBoth: any): Promise<
id: assistantId
})
if (!assistant) {
- throw new ApiError(StatusCodes.NOT_FOUND, `Assistant ${assistantId} not found`)
+ throw new InternalServerError(StatusCodes.NOT_FOUND, `Assistant ${assistantId} not found`)
}
try {
const assistantDetails = JSON.parse(assistant.details)
@@ -145,14 +145,14 @@ const deleteAssistant = async (assistantId: string, isDeleteBoth: any): Promise<
})
if (!credential) {
- throw new ApiError(StatusCodes.NOT_FOUND, `Credential ${assistant.credential} not found`)
+ throw new InternalServerError(StatusCodes.NOT_FOUND, `Credential ${assistant.credential} not found`)
}
// Decrpyt credentialData
const decryptedCredentialData = await decryptCredentialData(credential.encryptedData)
const openAIApiKey = decryptedCredentialData['openAIApiKey']
if (!openAIApiKey) {
- throw new ApiError(StatusCodes.NOT_FOUND, `OpenAI ApiKey not found`)
+ throw new InternalServerError(StatusCodes.NOT_FOUND, `OpenAI ApiKey not found`)
}
const openai = new OpenAI({ apiKey: openAIApiKey })
@@ -163,11 +163,11 @@ const deleteAssistant = async (assistantId: string, isDeleteBoth: any): Promise<
if (error.status === 404 && error.type === 'invalid_request_error') {
return 'OK'
} else {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error deleting assistant: ${error}`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error deleting assistant: ${error}`)
}
}
} catch (error) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: assistantsService.deleteTool - ${error}`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: assistantsService.deleteTool - ${error}`)
}
}
@@ -177,7 +177,7 @@ const getAllAssistants = async (): Promise => {
const dbResponse = await appServer.AppDataSource.getRepository(Assistant).find()
return dbResponse
} catch (error) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: assistantsService.getAllAssistants - ${error}`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: assistantsService.getAllAssistants - ${error}`)
}
}
@@ -188,11 +188,11 @@ const getAssistantById = async (assistantId: string): Promise => {
id: assistantId
})
if (!dbResponse) {
- throw new ApiError(StatusCodes.NOT_FOUND, `Assistant ${assistantId} not found`)
+ throw new InternalServerError(StatusCodes.NOT_FOUND, `Assistant ${assistantId} not found`)
}
return dbResponse
} catch (error) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: assistantsService.getAssistantById - ${error}`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: assistantsService.getAssistantById - ${error}`)
}
}
@@ -204,7 +204,7 @@ const updateAssistant = async (assistantId: string, requestBody: any): Promise endingNodeIds.includes(nd.id))
@@ -52,7 +52,7 @@ const checkIfChatflowIsValidForStreaming = async (chatflowId: string): Promise => {
}
return dbResponse
} catch (error) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.getAllChatflows - ${error}`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.getAllChatflows - ${error}`)
}
}
@@ -121,7 +127,7 @@ const getAllChatflows = async (): Promise => {
const dbResponse = await appServer.AppDataSource.getRepository(ChatFlow).find()
return dbResponse
} catch (error) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.getAllChatflows - ${error}`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.getAllChatflows - ${error}`)
}
}
@@ -136,11 +142,11 @@ const getChatflowByApiKey = async (apiKeyId: string): Promise => {
.orderBy('cf.name', 'ASC')
.getMany()
if (dbResponse.length < 1) {
- throw new ApiError(StatusCodes.NOT_FOUND, `Chatflow not found in the database!`)
+ throw new InternalServerError(StatusCodes.NOT_FOUND, `Chatflow not found in the database!`)
}
return dbResponse
} catch (error) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.getChatflowByApiKey - ${error}`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.getChatflowByApiKey - ${error}`)
}
}
@@ -151,11 +157,11 @@ const getChatflowById = async (chatflowId: string): Promise => {
id: chatflowId
})
if (!dbResponse) {
- throw new ApiError(StatusCodes.NOT_FOUND, `Chatflow ${chatflowId} not found in the database!`)
+ throw new InternalServerError(StatusCodes.NOT_FOUND, `Chatflow ${chatflowId} not found in the database!`)
}
return dbResponse
} catch (error) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.getAllChatflows - ${error}`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.getAllChatflows - ${error}`)
}
}
@@ -171,7 +177,7 @@ const saveChatflow = async (newChatFlow: ChatFlow): Promise => {
})
return dbResponse
} catch (error) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.saveChatflow - ${error}`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.saveChatflow - ${error}`)
}
}
@@ -188,7 +194,7 @@ const updateChatflow = async (chatflow: ChatFlow, updateChatFlow: ChatFlow): Pro
}
return dbResponse
} catch (error) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.updateChatflow - ${error}`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.updateChatflow - ${error}`)
}
}
@@ -202,11 +208,11 @@ const getSinglePublicChatflow = async (chatflowId: string): Promise => {
if (dbResponse && dbResponse.isPublic) {
return dbResponse
} else if (dbResponse && !dbResponse.isPublic) {
- throw new ApiError(StatusCodes.UNAUTHORIZED, `Unauthorized`)
+ throw new InternalServerError(StatusCodes.UNAUTHORIZED, `Unauthorized`)
}
- throw new ApiError(StatusCodes.NOT_FOUND, `Chatflow ${chatflowId} not found`)
+ throw new InternalServerError(StatusCodes.NOT_FOUND, `Chatflow ${chatflowId} not found`)
} catch (error) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.getSinglePublicChatflow - ${error}`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.getSinglePublicChatflow - ${error}`)
}
}
@@ -219,7 +225,7 @@ const getSinglePublicChatbotConfig = async (chatflowId: string): Promise =>
id: chatflowId
})
if (!dbResponse) {
- throw new ApiError(StatusCodes.NOT_FOUND, `Chatflow ${chatflowId} not found`)
+ throw new InternalServerError(StatusCodes.NOT_FOUND, `Chatflow ${chatflowId} not found`)
}
const uploadsConfig = await utilGetUploadsConfig(chatflowId)
// even if chatbotConfig is not set but uploads are enabled
@@ -229,12 +235,12 @@ const getSinglePublicChatbotConfig = async (chatflowId: string): Promise =>
const parsedConfig = dbResponse.chatbotConfig ? JSON.parse(dbResponse.chatbotConfig) : {}
return { ...parsedConfig, uploads: uploadsConfig }
} catch (e) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error parsing Chatbot Config for Chatflow ${chatflowId}`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error parsing Chatbot Config for Chatflow ${chatflowId}`)
}
}
return 'OK'
} catch (error) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.getSinglePublicChatbotConfig - ${error}`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.getSinglePublicChatbotConfig - ${error}`)
}
}
diff --git a/packages/server/src/services/credentials/index.ts b/packages/server/src/services/credentials/index.ts
index c8086b9a38e..e4ba157d24e 100644
--- a/packages/server/src/services/credentials/index.ts
+++ b/packages/server/src/services/credentials/index.ts
@@ -3,7 +3,7 @@ import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
import { Credential } from '../../database/entities/Credential'
import { transformToCredentialEntity, decryptCredentialData } from '../../utils'
import { ICredentialReturnResponse } from '../../Interface'
-import { ApiError } from '../../errors/apiError'
+import { InternalServerError } from '../../errors/internalServerError'
import { StatusCodes } from 'http-status-codes'
const createCredential = async (requestBody: any) => {
@@ -14,7 +14,7 @@ const createCredential = async (requestBody: any) => {
const dbResponse = await appServer.AppDataSource.getRepository(Credential).save(credential)
return dbResponse
} catch (error) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: credentialsService.createCredential - ${error}`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: credentialsService.createCredential - ${error}`)
}
}
@@ -24,11 +24,11 @@ const deleteCredentials = async (credentialId: string): Promise => {
const appServer = getRunningExpressApp()
const dbResponse = await appServer.AppDataSource.getRepository(Credential).delete({ id: credentialId })
if (!dbResponse) {
- throw new ApiError(StatusCodes.NOT_FOUND, `Credential ${credentialId} not found`)
+ throw new InternalServerError(StatusCodes.NOT_FOUND, `Credential ${credentialId} not found`)
}
return dbResponse
} catch (error) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: credentialsService.deleteCredential - ${error}`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: credentialsService.deleteCredential - ${error}`)
}
}
@@ -59,7 +59,7 @@ const getAllCredentials = async (paramCredentialName: any) => {
}
return dbResponse
} catch (error) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: credentialsService.getAllCredentials - ${error}`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: credentialsService.getAllCredentials - ${error}`)
}
}
@@ -70,7 +70,7 @@ const getCredentialById = async (credentialId: string): Promise => {
id: credentialId
})
if (!credential) {
- throw new ApiError(StatusCodes.NOT_FOUND, `Credential ${credentialId} not found`)
+ throw new InternalServerError(StatusCodes.NOT_FOUND, `Credential ${credentialId} not found`)
}
// Decrpyt credentialData
const decryptedCredentialData = await decryptCredentialData(
@@ -85,7 +85,7 @@ const getCredentialById = async (credentialId: string): Promise => {
const dbResponse = omit(returnCredential, ['encryptedData'])
return dbResponse
} catch (error) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: credentialsService.createCredential - ${error}`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: credentialsService.createCredential - ${error}`)
}
}
@@ -96,14 +96,14 @@ const updateCredential = async (credentialId: string, requestBody: any): Promise
id: credentialId
})
if (!credential) {
- throw new ApiError(StatusCodes.NOT_FOUND, `Credential ${credentialId} not found`)
+ throw new InternalServerError(StatusCodes.NOT_FOUND, `Credential ${credentialId} not found`)
}
const updateCredential = await transformToCredentialEntity(requestBody)
await appServer.AppDataSource.getRepository(Credential).merge(credential, updateCredential)
const dbResponse = await appServer.AppDataSource.getRepository(Credential).save(credential)
return dbResponse
} catch (error) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: credentialsService.updateCredential - ${error}`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: credentialsService.updateCredential - ${error}`)
}
}
diff --git a/packages/server/src/services/fetch-links/index.ts b/packages/server/src/services/fetch-links/index.ts
index dcf09a4b15e..b402696d418 100644
--- a/packages/server/src/services/fetch-links/index.ts
+++ b/packages/server/src/services/fetch-links/index.ts
@@ -1,12 +1,15 @@
import { webCrawl, xmlScrape } from 'flowise-components'
-import { ApiError } from '../../errors/apiError'
+import { InternalServerError } from '../../errors/internalServerError'
import { StatusCodes } from 'http-status-codes'
const getAllLinks = async (requestUrl: string, relativeLinksMethod: string, queryLimit: string): Promise => {
try {
const url = decodeURIComponent(requestUrl)
if (!relativeLinksMethod) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Please choose a Relative Links Method in Additional Parameters!`)
+ throw new InternalServerError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Please choose a Relative Links Method in Additional Parameters!`
+ )
}
const limit = parseInt(queryLimit)
if (process.env.DEBUG === 'true') console.info(`Start ${relativeLinksMethod}`)
@@ -18,7 +21,7 @@ const getAllLinks = async (requestUrl: string, relativeLinksMethod: string, quer
}
return dbResponse
} catch (error) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: fetchLinksService.getAllLinks - ${error}`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: fetchLinksService.getAllLinks - ${error}`)
}
}
diff --git a/packages/server/src/services/flow-configs/index.ts b/packages/server/src/services/flow-configs/index.ts
index 35c8494b407..cad25359640 100644
--- a/packages/server/src/services/flow-configs/index.ts
+++ b/packages/server/src/services/flow-configs/index.ts
@@ -2,7 +2,7 @@ import { findAvailableConfigs } from '../../utils'
import { IReactFlowObject } from '../../Interface'
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
import chatflowsService from '../chatflows'
-import { ApiError } from '../../errors/apiError'
+import { InternalServerError } from '../../errors/internalServerError'
import { StatusCodes } from 'http-status-codes'
const getSingleFlowConfig = async (chatflowId: string): Promise => {
@@ -10,7 +10,7 @@ const getSingleFlowConfig = async (chatflowId: string): Promise => {
const appServer = getRunningExpressApp()
const chatflow = await chatflowsService.getChatflowById(chatflowId)
if (!chatflow) {
- throw new ApiError(StatusCodes.NOT_FOUND, `Chatflow ${chatflowId} not found in the database!`)
+ throw new InternalServerError(StatusCodes.NOT_FOUND, `Chatflow ${chatflowId} not found in the database!`)
}
const flowData = chatflow.flowData
const parsedFlowData: IReactFlowObject = JSON.parse(flowData)
@@ -18,7 +18,7 @@ const getSingleFlowConfig = async (chatflowId: string): Promise => {
const dbResponse = findAvailableConfigs(nodes, appServer.nodesPool.componentCredentials)
return dbResponse
} catch (error) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: flowConfigService.getSingleFlowConfig - ${error}`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: flowConfigService.getSingleFlowConfig - ${error}`)
}
}
diff --git a/packages/server/src/services/nodes/index.ts b/packages/server/src/services/nodes/index.ts
index 4993f3b788e..0b5fd021bcd 100644
--- a/packages/server/src/services/nodes/index.ts
+++ b/packages/server/src/services/nodes/index.ts
@@ -4,7 +4,7 @@ import { INodeData } from '../../Interface'
import { INodeOptionsValue, ICommonObject, handleEscapeCharacters } from 'flowise-components'
import { databaseEntities } from '../../utils'
import logger from '../../utils/logger'
-import { ApiError } from '../../errors/apiError'
+import { InternalServerError } from '../../errors/internalServerError'
import { StatusCodes } from 'http-status-codes'
// Get all component nodes
@@ -18,7 +18,7 @@ const getAllNodes = async () => {
}
return dbResponse
} catch (error) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: nodesService.getAllNodes - ${error}`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: nodesService.getAllNodes - ${error}`)
}
}
@@ -30,10 +30,10 @@ const getNodeByName = async (nodeName: string) => {
const dbResponse = appServer.nodesPool.componentNodes[nodeName]
return dbResponse
} else {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Node ${nodeName} not found`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Node ${nodeName} not found`)
}
} catch (error) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: nodesService.getAllNodes - ${error}`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: nodesService.getAllNodes - ${error}`)
}
}
@@ -44,20 +44,20 @@ const getSingleNodeIcon = async (nodeName: string) => {
if (Object.prototype.hasOwnProperty.call(appServer.nodesPool.componentNodes, nodeName)) {
const nodeInstance = appServer.nodesPool.componentNodes[nodeName]
if (nodeInstance.icon === undefined) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Node ${nodeName} icon not found`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Node ${nodeName} icon not found`)
}
if (nodeInstance.icon.endsWith('.svg') || nodeInstance.icon.endsWith('.png') || nodeInstance.icon.endsWith('.jpg')) {
const filepath = nodeInstance.icon
return filepath
} else {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Node ${nodeName} icon is missing icon`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Node ${nodeName} icon is missing icon`)
}
} else {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Node ${nodeName} not found`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Node ${nodeName} not found`)
}
} catch (error) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: nodesService.getSingleNodeIcon - ${error}`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: nodesService.getSingleNodeIcon - ${error}`)
}
}
@@ -80,10 +80,10 @@ const getSingleNodeAsyncOptions = async (nodeName: string, requestBody: any): Pr
return []
}
} else {
- throw new ApiError(StatusCodes.NOT_FOUND, `Node ${nodeName} not found`)
+ throw new InternalServerError(StatusCodes.NOT_FOUND, `Node ${nodeName} not found`)
}
} catch (error) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: nodesService.getSingleNodeAsyncOptions - ${error}`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: nodesService.getSingleNodeAsyncOptions - ${error}`)
}
}
@@ -113,13 +113,13 @@ const executeCustomFunction = async (requestBody: any) => {
return dbResponse
} catch (error) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error running custom function: ${error}`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error running custom function: ${error}`)
}
} else {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Node customFunction not found`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Node customFunction not found`)
}
} catch (error) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: nodesService.executeCustomFunction - ${error}`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: nodesService.executeCustomFunction - ${error}`)
}
}
diff --git a/packages/server/src/services/openai-assistants/index.ts b/packages/server/src/services/openai-assistants/index.ts
index 96f822e920b..71ef35820d8 100644
--- a/packages/server/src/services/openai-assistants/index.ts
+++ b/packages/server/src/services/openai-assistants/index.ts
@@ -2,7 +2,7 @@ import OpenAI from 'openai'
import { decryptCredentialData } from '../../utils'
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
import { Credential } from '../../database/entities/Credential'
-import { ApiError } from '../../errors/apiError'
+import { InternalServerError } from '../../errors/internalServerError'
import { StatusCodes } from 'http-status-codes'
// ----------------------------------------
@@ -17,20 +17,20 @@ const getAllOpenaiAssistants = async (credentialId: string): Promise => {
id: credentialId
})
if (!credential) {
- throw new ApiError(StatusCodes.NOT_FOUND, `Credential ${credentialId} not found in the database!`)
+ throw new InternalServerError(StatusCodes.NOT_FOUND, `Credential ${credentialId} not found in the database!`)
}
// Decrpyt credentialData
const decryptedCredentialData = await decryptCredentialData(credential.encryptedData)
const openAIApiKey = decryptedCredentialData['openAIApiKey']
if (!openAIApiKey) {
- throw new ApiError(StatusCodes.NOT_FOUND, `OpenAI ApiKey not found`)
+ throw new InternalServerError(StatusCodes.NOT_FOUND, `OpenAI ApiKey not found`)
}
const openai = new OpenAI({ apiKey: openAIApiKey })
const retrievedAssistants = await openai.beta.assistants.list()
const dbResponse = retrievedAssistants.data
return dbResponse
} catch (error) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: openaiAssistantsService.getAllOpenaiAssistants - ${error}`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: openaiAssistantsService.getAllOpenaiAssistants - ${error}`)
}
}
@@ -42,13 +42,13 @@ const getSingleOpenaiAssistant = async (credentialId: string, assistantId: strin
id: credentialId
})
if (!credential) {
- throw new ApiError(StatusCodes.NOT_FOUND, `Credential ${credentialId} not found in the database!`)
+ throw new InternalServerError(StatusCodes.NOT_FOUND, `Credential ${credentialId} not found in the database!`)
}
// Decrpyt credentialData
const decryptedCredentialData = await decryptCredentialData(credential.encryptedData)
const openAIApiKey = decryptedCredentialData['openAIApiKey']
if (!openAIApiKey) {
- throw new ApiError(StatusCodes.NOT_FOUND, `OpenAI ApiKey not found`)
+ throw new InternalServerError(StatusCodes.NOT_FOUND, `OpenAI ApiKey not found`)
}
const openai = new OpenAI({ apiKey: openAIApiKey })
@@ -60,7 +60,10 @@ const getSingleOpenaiAssistant = async (credentialId: string, assistantId: strin
}
return dbResponse
} catch (error) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: openaiAssistantsService.getSingleOpenaiAssistant - ${error}`)
+ throw new InternalServerError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: openaiAssistantsService.getSingleOpenaiAssistant - ${error}`
+ )
}
}
diff --git a/packages/server/src/services/predictions/index.ts b/packages/server/src/services/predictions/index.ts
index c00374679ab..232de30b4d9 100644
--- a/packages/server/src/services/predictions/index.ts
+++ b/packages/server/src/services/predictions/index.ts
@@ -1,7 +1,7 @@
import { StatusCodes } from 'http-status-codes'
import { utilBuildChatflow } from '../../utils/buildChatflow'
import { Server } from 'socket.io'
-import { ApiError } from '../../errors/apiError'
+import { InternalServerError } from '../../errors/internalServerError'
import { Request } from 'express'
const buildChatflow = async (fullRequest: Request, ioServer: Server) => {
@@ -9,7 +9,7 @@ const buildChatflow = async (fullRequest: Request, ioServer: Server) => {
const dbResponse = await utilBuildChatflow(fullRequest, ioServer)
return dbResponse
} catch (error) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, 'Error: predictionsServices.buildChatflow failed!')
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, 'Error: predictionsServices.buildChatflow failed!')
}
}
diff --git a/packages/server/src/services/tools/index.ts b/packages/server/src/services/tools/index.ts
index 886fb7778eb..b9f183d0e20 100644
--- a/packages/server/src/services/tools/index.ts
+++ b/packages/server/src/services/tools/index.ts
@@ -1,7 +1,7 @@
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
import { Tool } from '../../database/entities/Tool'
import { getAppVersion } from '../../utils'
-import { ApiError } from '../../errors/apiError'
+import { InternalServerError } from '../../errors/internalServerError'
import { StatusCodes } from 'http-status-codes'
const creatTool = async (requestBody: any): Promise => {
@@ -18,7 +18,7 @@ const creatTool = async (requestBody: any): Promise => {
})
return dbResponse
} catch (error) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: toolsService.creatTool - ${error}`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: toolsService.creatTool - ${error}`)
}
}
@@ -30,7 +30,7 @@ const deleteTool = async (toolId: string): Promise => {
})
return dbResponse
} catch (error) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: toolsService.deleteTool - ${error}`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: toolsService.deleteTool - ${error}`)
}
}
@@ -40,7 +40,7 @@ const getAllTools = async (): Promise => {
const dbResponse = await appServer.AppDataSource.getRepository(Tool).find()
return dbResponse
} catch (error) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: toolsService.getAllTools - ${error}`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: toolsService.getAllTools - ${error}`)
}
}
@@ -51,11 +51,11 @@ const getToolById = async (toolId: string): Promise => {
id: toolId
})
if (!dbResponse) {
- throw new ApiError(StatusCodes.NOT_FOUND, `Tool ${toolId} not found`)
+ throw new InternalServerError(StatusCodes.NOT_FOUND, `Tool ${toolId} not found`)
}
return dbResponse
} catch (error) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: toolsService.getToolById - ${error}`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: toolsService.getToolById - ${error}`)
}
}
@@ -66,7 +66,7 @@ const updateTool = async (toolId: string, toolBody: any): Promise => {
id: toolId
})
if (!tool) {
- throw new ApiError(StatusCodes.NOT_FOUND, `Tool ${toolId} not found`)
+ throw new InternalServerError(StatusCodes.NOT_FOUND, `Tool ${toolId} not found`)
}
const updateTool = new Tool()
Object.assign(updateTool, toolBody)
@@ -74,7 +74,7 @@ const updateTool = async (toolId: string, toolBody: any): Promise => {
const dbResponse = await appServer.AppDataSource.getRepository(Tool).save(tool)
return dbResponse
} catch (error) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: toolsService.getToolById - ${error}`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: toolsService.getToolById - ${error}`)
}
}
diff --git a/packages/server/src/services/versions/index.ts b/packages/server/src/services/versions/index.ts
index cbf5eba41e6..3cd40b4bb8c 100644
--- a/packages/server/src/services/versions/index.ts
+++ b/packages/server/src/services/versions/index.ts
@@ -1,6 +1,6 @@
import path from 'path'
import * as fs from 'fs'
-import { ApiError } from '../../errors/apiError'
+import { InternalServerError } from '../../errors/internalServerError'
import { StatusCodes } from 'http-status-codes'
const getVersion = async () => {
@@ -22,7 +22,7 @@ const getVersion = async () => {
}
const packagejsonPath = getPackageJsonPath()
if (!packagejsonPath) {
- throw new ApiError(StatusCodes.NOT_FOUND, `Version not found`)
+ throw new InternalServerError(StatusCodes.NOT_FOUND, `Version not found`)
}
try {
const content = await fs.promises.readFile(packagejsonPath, 'utf8')
@@ -31,10 +31,10 @@ const getVersion = async () => {
version: parsedContent.version
}
} catch (error) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Version not found: ${error}`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Version not found: ${error}`)
}
} catch (error) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: versionService.getVersion - ${error}`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: versionService.getVersion - ${error}`)
}
}
diff --git a/packages/server/src/utils/buildChatflow.ts b/packages/server/src/utils/buildChatflow.ts
index c7e35cc9249..4a36d8f3b45 100644
--- a/packages/server/src/utils/buildChatflow.ts
+++ b/packages/server/src/utils/buildChatflow.ts
@@ -3,7 +3,7 @@ import { IFileUpload, getStoragePath, convertSpeechToText, ICommonObject } from
import { StatusCodes } from 'http-status-codes'
import { IncomingInput, IMessage, INodeData, IReactFlowObject, IReactFlowNode, IDepthQueue, chatType, IChatMessage } from '../Interface'
import path from 'path'
-import { ApiError } from '../errors/apiError'
+import { InternalServerError } from '../errors/internalServerError'
import { ChatFlow } from '../database/entities/ChatFlow'
import { Server } from 'socket.io'
import { getRunningExpressApp } from '../utils/getRunningExpressApp'
@@ -48,7 +48,7 @@ export const utilBuildChatflow = async (req: Request, socketIO?: Server, isInter
id: chatflowid
})
if (!chatflow) {
- throw new ApiError(StatusCodes.NOT_FOUND, `Chatflow ${chatflowid} not found`)
+ throw new InternalServerError(StatusCodes.NOT_FOUND, `Chatflow ${chatflowid} not found`)
}
const chatId = incomingInput.chatId ?? incomingInput.overrideConfig?.sessionId ?? uuidv4()
@@ -57,7 +57,7 @@ export const utilBuildChatflow = async (req: Request, socketIO?: Server, isInter
if (!isInternal) {
const isKeyValidated = await utilValidateKey(req, chatflow)
if (!isKeyValidated) {
- throw new ApiError(StatusCodes.UNAUTHORIZED, `Unauthorized`)
+ throw new InternalServerError(StatusCodes.UNAUTHORIZED, `Unauthorized`)
}
}
@@ -182,7 +182,7 @@ export const utilBuildChatflow = async (req: Request, socketIO?: Server, isInter
const directedGraph = graph
const endingNodeIds = getEndingNodes(nodeDependencies, directedGraph)
if (!endingNodeIds.length) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Ending nodes not found`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Ending nodes not found`)
}
const endingNodes = nodes.filter((nd) => endingNodeIds.includes(nd.id))
@@ -192,7 +192,7 @@ export const utilBuildChatflow = async (req: Request, socketIO?: Server, isInter
for (const endingNode of endingNodes) {
const endingNodeData = endingNode.data
if (!endingNodeData) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Ending node ${endingNode.id} data not found`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Ending node ${endingNode.id} data not found`)
}
const isEndingNode = endingNodeData?.outputs?.output === 'EndingNode'
@@ -204,7 +204,7 @@ export const utilBuildChatflow = async (req: Request, socketIO?: Server, isInter
endingNodeData.category !== 'Agents' &&
endingNodeData.category !== 'Engine'
) {
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Ending node must be either a Chain or Agent`)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Ending node must be either a Chain or Agent`)
}
if (
@@ -212,7 +212,7 @@ export const utilBuildChatflow = async (req: Request, socketIO?: Server, isInter
Object.keys(endingNodeData.outputs).length &&
!Object.values(endingNodeData.outputs ?? {}).includes(endingNodeData.name)
) {
- throw new ApiError(
+ throw new InternalServerError(
StatusCodes.INTERNAL_SERVER_ERROR,
`Output of ${endingNodeData.label} (${endingNodeData.id}) must be ${endingNodeData.label}, can't be an Output Prediction`
)
@@ -291,7 +291,7 @@ export const utilBuildChatflow = async (req: Request, socketIO?: Server, isInter
? reactFlowNodes.find((node: IReactFlowNode) => endingNodeIds[0] === node.id)
: reactFlowNodes[reactFlowNodes.length - 1]
if (!nodeToExecute) {
- throw new ApiError(StatusCodes.NOT_FOUND, `Node not found`)
+ throw new InternalServerError(StatusCodes.NOT_FOUND, `Node not found`)
}
if (incomingInput.overrideConfig) {
@@ -393,6 +393,6 @@ export const utilBuildChatflow = async (req: Request, socketIO?: Server, isInter
return result
} catch (e: any) {
logger.error('[server]: Error:', e)
- throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, e.message)
+ throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, e.message)
}
}
From 734472fba2e316cfff24fc3903e9f1adc49621de Mon Sep 17 00:00:00 2001
From: ocflowiseai <154992625+ocflowiseai@users.noreply.github.com>
Date: Mon, 8 Apr 2024 10:25:03 +0200
Subject: [PATCH 13/18] Use InternalFlowiseError in controllers
---
.../server/src/controllers/apikey/index.ts | 12 +++---
.../src/controllers/assistants/index.ts | 27 +++++++++---
.../src/controllers/chat-messages/index.ts | 17 ++++++--
.../server/src/controllers/chatflows/index.ts | 29 +++++++++----
.../components-credentials/index.ts | 12 +++++-
.../src/controllers/credentials/index.ts | 27 +++++++++---
.../server/src/controllers/feedback/index.ts | 22 ++++++++--
.../src/controllers/fetch-links/index.ts | 11 +++--
.../src/controllers/flow-configs/index.ts | 7 +++-
packages/server/src/controllers/ip/index.ts | 7 +++-
.../src/controllers/load-prompts/index.ts | 7 +++-
.../src/controllers/node-configs/index.ts | 7 +++-
.../src/controllers/node-icons/index.ts | 17 ++++++--
.../server/src/controllers/nodes/index.ts | 21 +++++++---
.../controllers/openai-assistants/index.ts | 17 ++++++--
.../src/controllers/predictions/index.ts | 10 ++---
.../index.ts | 2 +-
.../server/src/middlewares/errors/index.ts | 4 +-
packages/server/src/services/apikey/index.ts | 4 +-
.../server/src/services/assistants/index.ts | 38 ++++++++---------
.../server/src/services/chatflows/index.ts | 42 +++++++++----------
.../server/src/services/credentials/index.ts | 18 ++++----
.../server/src/services/fetch-links/index.ts | 6 +--
.../server/src/services/flow-configs/index.ts | 6 +--
packages/server/src/services/nodes/index.ts | 26 ++++++------
.../src/services/openai-assistants/index.ts | 17 ++++----
.../server/src/services/predictions/index.ts | 4 +-
packages/server/src/services/tools/index.ts | 16 +++----
.../server/src/services/versions/index.ts | 8 ++--
packages/server/src/utils/buildChatflow.ts | 18 ++++----
30 files changed, 299 insertions(+), 160 deletions(-)
rename packages/server/src/errors/{internalServerError => internalFlowiseError}/index.ts (84%)
diff --git a/packages/server/src/controllers/apikey/index.ts b/packages/server/src/controllers/apikey/index.ts
index b465cb6653e..26483b54293 100644
--- a/packages/server/src/controllers/apikey/index.ts
+++ b/packages/server/src/controllers/apikey/index.ts
@@ -1,6 +1,6 @@
import { Request, Response, NextFunction } from 'express'
import { StatusCodes } from 'http-status-codes'
-import { InternalServerError } from '../../errors/internalServerError'
+import { InternalFlowiseError } from '../../errors/internalFlowiseError'
import apikeyService from '../../services/apikey'
// Get api keys
@@ -16,7 +16,7 @@ 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 InternalServerError(StatusCodes.PRECONDITION_FAILED, `Error: apikeyController.createApiKey - keyName not provided!`)
+ throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: apikeyController.createApiKey - keyName not provided!`)
}
const apiResponse = await apikeyService.createApiKey(req.body.keyName)
return res.json(apiResponse)
@@ -29,10 +29,10 @@ const createApiKey = async (req: Request, res: Response, next: NextFunction) =>
const updateApiKey = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.params.id === 'undefined' || req.params.id === '') {
- throw new InternalServerError(StatusCodes.PRECONDITION_FAILED, `Error: apikeyController.updateApiKey - id not provided!`)
+ throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: apikeyController.updateApiKey - id not provided!`)
}
if (typeof req.body.keyName === 'undefined' || req.body.keyName === '') {
- throw new InternalServerError(StatusCodes.PRECONDITION_FAILED, `Error: apikeyController.updateApiKey - keyName not provided!`)
+ 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)
@@ -45,7 +45,7 @@ const updateApiKey = async (req: Request, res: Response, next: NextFunction) =>
const deleteApiKey = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.params.id === 'undefined' || req.params.id === '') {
- throw new InternalServerError(StatusCodes.PRECONDITION_FAILED, `Error: apikeyController.deleteApiKey - id not provided!`)
+ throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: apikeyController.deleteApiKey - id not provided!`)
}
const apiResponse = await apikeyService.deleteApiKey(req.params.id)
return res.json(apiResponse)
@@ -58,7 +58,7 @@ const deleteApiKey = async (req: Request, res: Response, next: NextFunction) =>
const verifyApiKey = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.params.apiKey === 'undefined' || req.params.apiKey === '') {
- throw new InternalServerError(StatusCodes.PRECONDITION_FAILED, `Error: apikeyController.verifyApiKey - apiKey not provided!`)
+ throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: apikeyController.verifyApiKey - apiKey not provided!`)
}
const apiResponse = await apikeyService.verifyApiKey(req.params.apiKey)
return res.json(apiResponse)
diff --git a/packages/server/src/controllers/assistants/index.ts b/packages/server/src/controllers/assistants/index.ts
index e6d97570936..fbfa106ab34 100644
--- a/packages/server/src/controllers/assistants/index.ts
+++ b/packages/server/src/controllers/assistants/index.ts
@@ -1,10 +1,15 @@
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) => {
try {
if (typeof req.body === 'undefined' || req.body === '') {
- throw new Error(`Error: assistantsController.creatAssistant - body not provided!`)
+ throw new InternalFlowiseError(
+ StatusCodes.PRECONDITION_FAILED,
+ `Error: assistantsController.creatAssistant - body not provided!`
+ )
}
const apiResponse = await assistantsService.creatAssistant(req.body)
return res.json(apiResponse)
@@ -16,7 +21,10 @@ 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!`)
+ throw new InternalFlowiseError(
+ StatusCodes.PRECONDITION_FAILED,
+ `Error: assistantsController.deleteAssistant - id not provided!`
+ )
}
const apiResponse = await assistantsService.deleteAssistant(req.params.id, req.query.isDeleteBoth)
@@ -39,7 +47,10 @@ 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!`)
+ throw new InternalFlowiseError(
+ StatusCodes.PRECONDITION_FAILED,
+ `Error: assistantsController.getAssistantById - id not provided!`
+ )
}
const apiResponse = await assistantsService.getAssistantById(req.params.id)
@@ -52,10 +63,16 @@ 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!`)
+ 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!`)
+ throw new InternalFlowiseError(
+ StatusCodes.PRECONDITION_FAILED,
+ `Error: assistantsController.updateAssistant - body not provided!`
+ )
}
const apiResponse = await assistantsService.updateAssistant(req.params.id, req.body)
diff --git a/packages/server/src/controllers/chat-messages/index.ts b/packages/server/src/controllers/chat-messages/index.ts
index cb0e26f2fb4..d418f4bf834 100644
--- a/packages/server/src/controllers/chat-messages/index.ts
+++ b/packages/server/src/controllers/chat-messages/index.ts
@@ -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!')
+ throw new InternalFlowiseError(
+ StatusCodes.PRECONDITION_FAILED,
+ 'Error: chatMessagesController.createChatMessage - request body not provided!'
+ )
}
const apiResponse = await chatMessagesService.createChatMessage(req.body)
return res.json(apiResponse)
@@ -45,7 +50,10 @@ const getAllChatMessages = async (req: Request, res: Response, next: NextFunctio
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!`)
+ throw new InternalFlowiseError(
+ StatusCodes.PRECONDITION_FAILED,
+ `Error: chatMessageController.getAllChatMessages - id not provided!`
+ )
}
const apiResponse = await chatMessagesService.getAllChatMessages(
req.params.id,
@@ -98,7 +106,10 @@ const removeAllChatMessages = async (req: Request, res: Response, next: NextFunc
try {
const appServer = getRunningExpressApp()
if (typeof req.params.id === 'undefined' || req.params.id === '') {
- throw new Error('Error: chatMessagesController.removeAllChatMessages - id not provided!')
+ 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)
diff --git a/packages/server/src/controllers/chatflows/index.ts b/packages/server/src/controllers/chatflows/index.ts
index f6169edfbcf..ddfdb3e5add 100644
--- a/packages/server/src/controllers/chatflows/index.ts
+++ b/packages/server/src/controllers/chatflows/index.ts
@@ -3,11 +3,16 @@ 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!`)
+ throw new InternalFlowiseError(
+ StatusCodes.PRECONDITION_FAILED,
+ `Error: chatflowsRouter.checkIfChatflowIsValidForStreaming - id not provided!`
+ )
}
const apiResponse = await chatflowsService.checkIfChatflowIsValidForStreaming(req.params.id)
return res.json(apiResponse)
@@ -19,7 +24,10 @@ 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!`)
+ throw new InternalFlowiseError(
+ StatusCodes.PRECONDITION_FAILED,
+ `Error: chatflowsRouter.checkIfChatflowIsValidForUploads - id not provided!`
+ )
}
const apiResponse = await chatflowsService.checkIfChatflowIsValidForUploads(req.params.id)
return res.json(apiResponse)
@@ -31,7 +39,7 @@ 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!`)
+ throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: chatflowsRouter.deleteChatflow - id not provided!`)
}
const apiResponse = await chatflowsService.deleteChatflow(req.params.id)
return res.json(apiResponse)
@@ -53,7 +61,7 @@ const getAllChatflows = async (req: Request, res: Response, next: NextFunction)
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!`)
+ throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: chatflowsRouter.getChatflowById - apiKey not provided!`)
}
const apiKey = await getApiKey(req.params.apiKey)
if (!apiKey) {
@@ -69,7 +77,7 @@ 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!`)
+ throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: chatflowsRouter.getChatflowById - id not provided!`)
}
const apiResponse = await chatflowsService.getChatflowById(req.params.id)
return res.json(apiResponse)
@@ -81,7 +89,7 @@ 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!`)
+ throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: chatflowsRouter.saveChatflow - body not provided!`)
}
const body = req.body
const newChatFlow = new ChatFlow()
@@ -96,7 +104,7 @@ 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!`)
+ throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: chatflowsRouter.updateChatflow - id not provided!`)
}
const chatflow = await chatflowsService.getChatflowById(req.params.id)
if (!chatflow) {
@@ -120,7 +128,7 @@ 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!`)
+ throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: chatflowsRouter.updateChatflow - id not provided!`)
}
const apiResponse = await chatflowsService.getSinglePublicChatflow(req.params.id)
return res.json(apiResponse)
@@ -132,7 +140,10 @@ 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!`)
+ throw new InternalFlowiseError(
+ StatusCodes.PRECONDITION_FAILED,
+ `Error: chatflowsRouter.getSinglePublicChatbotConfig - id not provided!`
+ )
}
const apiResponse = await chatflowsService.getSinglePublicChatbotConfig(req.params.id)
return res.json(apiResponse)
diff --git a/packages/server/src/controllers/components-credentials/index.ts b/packages/server/src/controllers/components-credentials/index.ts
index 5f16aa4646c..32784d836f0 100644
--- a/packages/server/src/controllers/components-credentials/index.ts
+++ b/packages/server/src/controllers/components-credentials/index.ts
@@ -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) => {
@@ -15,7 +17,10 @@ const getAllComponentsCredentials = async (req: Request, res: Response, next: Ne
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!`)
+ throw new InternalFlowiseError(
+ StatusCodes.PRECONDITION_FAILED,
+ `Error: componentsCredentialsController.getComponentByName - name not provided!`
+ )
}
const apiResponse = await componentsCredentialsService.getComponentByName(req.params.name)
return res.json(apiResponse)
@@ -28,7 +33,10 @@ const getComponentByName = async (req: Request, res: Response, next: NextFunctio
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!`)
+ throw new InternalFlowiseError(
+ StatusCodes.PRECONDITION_FAILED,
+ `Error: componentsCredentialsController.getSingleComponentsCredentialIcon - name not provided!`
+ )
}
const apiResponse = await componentsCredentialsService.getSingleComponentsCredentialIcon(req.params.name)
return res.sendFile(apiResponse)
diff --git a/packages/server/src/controllers/credentials/index.ts b/packages/server/src/controllers/credentials/index.ts
index 0dea25095a8..2be8945cc8c 100644
--- a/packages/server/src/controllers/credentials/index.ts
+++ b/packages/server/src/controllers/credentials/index.ts
@@ -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!`)
+ throw new InternalFlowiseError(
+ StatusCodes.PRECONDITION_FAILED,
+ `Error: credentialsController.createCredential - body not provided!`
+ )
}
const apiResponse = await credentialsService.createCredential(req.body)
return res.json(apiResponse)
@@ -16,7 +21,10 @@ 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!`)
+ throw new InternalFlowiseError(
+ StatusCodes.PRECONDITION_FAILED,
+ `Error: credentialsController.deleteCredentials - id not provided!`
+ )
}
const apiResponse = await credentialsService.deleteCredentials(req.params.id)
return res.json(apiResponse)
@@ -37,7 +45,10 @@ 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!`)
+ throw new InternalFlowiseError(
+ StatusCodes.PRECONDITION_FAILED,
+ `Error: credentialsController.getCredentialById - id not provided!`
+ )
}
const apiResponse = await credentialsService.getCredentialById(req.params.id)
return res.json(apiResponse)
@@ -49,10 +60,16 @@ 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!`)
+ 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!`)
+ throw new InternalFlowiseError(
+ StatusCodes.PRECONDITION_FAILED,
+ `Error: credentialsController.updateCredential - body not provided!`
+ )
}
const apiResponse = await credentialsService.updateCredential(req.params.id, req.body)
return res.json(apiResponse)
diff --git a/packages/server/src/controllers/feedback/index.ts b/packages/server/src/controllers/feedback/index.ts
index 08c95aff03c..0501a62a3c0 100644
--- a/packages/server/src/controllers/feedback/index.ts
+++ b/packages/server/src/controllers/feedback/index.ts
@@ -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!`)
+ 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
@@ -21,7 +26,10 @@ 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!`)
+ throw new InternalFlowiseError(
+ StatusCodes.PRECONDITION_FAILED,
+ `Error: feedbackController.createChatMessageFeedbackForChatflow - body not provided!`
+ )
}
const apiResponse = await feedbackService.createChatMessageFeedbackForChatflow(req.body)
return res.json(apiResponse)
@@ -33,10 +41,16 @@ 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!`)
+ 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!`)
+ 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)
diff --git a/packages/server/src/controllers/fetch-links/index.ts b/packages/server/src/controllers/fetch-links/index.ts
index 7f32d690e59..10f5a486be9 100644
--- a/packages/server/src/controllers/fetch-links/index.ts
+++ b/packages/server/src/controllers/fetch-links/index.ts
@@ -1,16 +1,21 @@
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!`)
+ 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!`)
+ 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!`)
+ throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: fetchLinksController.getAllLinks - limit not provided!`)
}
const apiResponse = await fetchLinksService.getAllLinks(
req.query.url as string,
diff --git a/packages/server/src/controllers/flow-configs/index.ts b/packages/server/src/controllers/flow-configs/index.ts
index fba673d2cbf..b8acd9012e4 100644
--- a/packages/server/src/controllers/flow-configs/index.ts
+++ b/packages/server/src/controllers/flow-configs/index.ts
@@ -1,10 +1,15 @@
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!`)
+ throw new InternalFlowiseError(
+ StatusCodes.PRECONDITION_FAILED,
+ `Error: flowConfigsController.getSingleFlowConfig - id not provided!`
+ )
}
const apiResponse = await flowConfigsService.getSingleFlowConfig(req.params.id)
return res.json(apiResponse)
diff --git a/packages/server/src/controllers/ip/index.ts b/packages/server/src/controllers/ip/index.ts
index 98f4ce729cd..6775f9f5ce2 100644
--- a/packages/server/src/controllers/ip/index.ts
+++ b/packages/server/src/controllers/ip/index.ts
@@ -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,
diff --git a/packages/server/src/controllers/load-prompts/index.ts b/packages/server/src/controllers/load-prompts/index.ts
index c428aa6faf0..4e4a3acbcfc 100644
--- a/packages/server/src/controllers/load-prompts/index.ts
+++ b/packages/server/src/controllers/load-prompts/index.ts
@@ -1,10 +1,15 @@
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!`)
+ throw new InternalFlowiseError(
+ StatusCodes.PRECONDITION_FAILED,
+ `Error: loadPromptsController.createPrompt - promptName not provided!`
+ )
}
const apiResponse = await loadPromptsService.createPrompt(req.body.promptName as string)
return res.json(apiResponse)
diff --git a/packages/server/src/controllers/node-configs/index.ts b/packages/server/src/controllers/node-configs/index.ts
index f8f90e1e8bb..fe2903a1734 100644
--- a/packages/server/src/controllers/node-configs/index.ts
+++ b/packages/server/src/controllers/node-configs/index.ts
@@ -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!`)
+ throw new InternalFlowiseError(
+ StatusCodes.PRECONDITION_FAILED,
+ `Error: nodeConfigsController.getAllNodeConfigs - body not provided!`
+ )
}
const apiResponse = await nodeConfigsService.getAllNodeConfigs(req.body)
return res.json(apiResponse)
diff --git a/packages/server/src/controllers/node-icons/index.ts b/packages/server/src/controllers/node-icons/index.ts
index b423a96fede..9d296ee63ab 100644
--- a/packages/server/src/controllers/node-icons/index.ts
+++ b/packages/server/src/controllers/node-icons/index.ts
@@ -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.PRECONDITION_FAILED,
+ `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.PRECONDITION_FAILED,
+ `Error: nodeIconController.getSingleNodeIcon - Node ${req.params.name} not found`
+ )
}
} catch (error) {
next(error)
diff --git a/packages/server/src/controllers/nodes/index.ts b/packages/server/src/controllers/nodes/index.ts
index efd5a68e82b..0d815f332c9 100644
--- a/packages/server/src/controllers/nodes/index.ts
+++ b/packages/server/src/controllers/nodes/index.ts
@@ -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 {
@@ -13,7 +15,7 @@ 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!`)
+ throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: nodesController.getNodeByName - name not provided!`)
}
const apiResponse = await nodesService.getNodeByName(req.params.name)
return res.json(apiResponse)
@@ -25,7 +27,7 @@ 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!`)
+ throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: nodesController.getSingleNodeIcon - name not provided!`)
}
const apiResponse = await nodesService.getSingleNodeIcon(req.params.name)
return res.sendFile(apiResponse)
@@ -37,10 +39,16 @@ 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!`)
+ 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!`)
+ throw new InternalFlowiseError(
+ StatusCodes.PRECONDITION_FAILED,
+ `Error: nodesController.getSingleNodeAsyncOptions - name not provided!`
+ )
}
const apiResponse = await nodesService.getSingleNodeAsyncOptions(req.params.name, req.body)
return res.json(apiResponse)
@@ -52,7 +60,10 @@ 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!`)
+ throw new InternalFlowiseError(
+ StatusCodes.PRECONDITION_FAILED,
+ `Error: nodesController.executeCustomFunction - body not provided!`
+ )
}
const apiResponse = await nodesService.executeCustomFunction(req.body)
return res.json(apiResponse)
diff --git a/packages/server/src/controllers/openai-assistants/index.ts b/packages/server/src/controllers/openai-assistants/index.ts
index e411b0b389b..dc36db52ee9 100644
--- a/packages/server/src/controllers/openai-assistants/index.ts
+++ b/packages/server/src/controllers/openai-assistants/index.ts
@@ -4,12 +4,17 @@ 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!`)
+ throw new InternalFlowiseError(
+ StatusCodes.PRECONDITION_FAILED,
+ `Error: openaiAssistantsController.getAllOpenaiAssistants - credential not provided!`
+ )
}
const apiResponse = await openaiAssistantsService.getAllOpenaiAssistants(req.query.credential as string)
return res.json(apiResponse)
@@ -22,10 +27,16 @@ const getAllOpenaiAssistants = async (req: Request, res: Response, next: NextFun
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!`)
+ 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!`)
+ 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)
return res.json(apiResponse)
diff --git a/packages/server/src/controllers/predictions/index.ts b/packages/server/src/controllers/predictions/index.ts
index eea642e68cb..3816f40e67a 100644
--- a/packages/server/src/controllers/predictions/index.ts
+++ b/packages/server/src/controllers/predictions/index.ts
@@ -3,27 +3,27 @@ import { getRateLimiter } from '../../utils/rateLimit'
import chatflowsService from '../../services/chatflows'
import logger from '../../utils/logger'
import predictionsServices from '../../services/predictions'
-import { InternalServerError } from '../../errors/internalServerError'
+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 InternalServerError(
+ throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: predictionsController.createPrediction - id not provided!`
)
}
if (typeof req.body === 'undefined' || req.body === '') {
- throw new InternalServerError(
+ throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: predictionsController.createPrediction - body not provided!`
)
}
const chatflow = await chatflowsService.getChatflowById(req.params.id)
if (!chatflow) {
- throw new InternalServerError(StatusCodes.NOT_FOUND, `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}`)
@@ -50,7 +50,7 @@ const createPrediction = async (req: Request, res: Response, next: NextFunction)
const apiResponse = await predictionsServices.buildChatflow(req, req?.io)
return res.json(apiResponse)
} else {
- throw new InternalServerError(StatusCodes.UNAUTHORIZED, `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)
diff --git a/packages/server/src/errors/internalServerError/index.ts b/packages/server/src/errors/internalFlowiseError/index.ts
similarity index 84%
rename from packages/server/src/errors/internalServerError/index.ts
rename to packages/server/src/errors/internalFlowiseError/index.ts
index 0b37eff5b1c..4e83651410c 100644
--- a/packages/server/src/errors/internalServerError/index.ts
+++ b/packages/server/src/errors/internalFlowiseError/index.ts
@@ -1,4 +1,4 @@
-export class InternalServerError extends Error {
+export class InternalFlowiseError extends Error {
statusCode: number
constructor(statusCode: number, message: string) {
super(message)
diff --git a/packages/server/src/middlewares/errors/index.ts b/packages/server/src/middlewares/errors/index.ts
index 1a00f14b441..ea0ab513ae8 100644
--- a/packages/server/src/middlewares/errors/index.ts
+++ b/packages/server/src/middlewares/errors/index.ts
@@ -1,10 +1,10 @@
import { NextFunction, Request, Response } from 'express'
import { StatusCodes } from 'http-status-codes'
-import { InternalServerError } from '../../errors/internalServerError'
+import { InternalFlowiseError } from '../../errors/internalFlowiseError'
// we need eslint because we have to pass next arg for the error middleware
// eslint-disable-next-line
-async function errorHandlerMiddleware(err: InternalServerError, req: Request, res: Response, next: NextFunction) {
+async function errorHandlerMiddleware(err: InternalFlowiseError, req: Request, res: Response, next: NextFunction) {
let displayedError = {
statusCode: err.statusCode || StatusCodes.INTERNAL_SERVER_ERROR,
success: false,
diff --git a/packages/server/src/services/apikey/index.ts b/packages/server/src/services/apikey/index.ts
index 86de1eef223..988b42ec2a9 100644
--- a/packages/server/src/services/apikey/index.ts
+++ b/packages/server/src/services/apikey/index.ts
@@ -1,7 +1,7 @@
import { addAPIKey, deleteAPIKey, getAPIKeys, updateAPIKey } from '../../utils/apiKey'
import { addChatflowsCount } from '../../utils/addChatflowsCount'
import { getApiKey } from '../../utils/apiKey'
-import { InternalServerError } from '../../errors/internalServerError'
+import { InternalFlowiseError } from '../../errors/internalFlowiseError'
import { StatusCodes } from 'http-status-codes'
const getAllApiKeys = async () => {
@@ -49,7 +49,7 @@ const verifyApiKey = async (paramApiKey: string): Promise => {
try {
const apiKey = await getApiKey(paramApiKey)
if (!apiKey) {
- throw new InternalServerError(StatusCodes.UNAUTHORIZED, `Unauthorized`)
+ throw new InternalFlowiseError(StatusCodes.UNAUTHORIZED, `Unauthorized`)
}
const dbResponse = 'OK'
return dbResponse
diff --git a/packages/server/src/services/assistants/index.ts b/packages/server/src/services/assistants/index.ts
index 25259ead777..394ed96ee92 100644
--- a/packages/server/src/services/assistants/index.ts
+++ b/packages/server/src/services/assistants/index.ts
@@ -6,14 +6,14 @@ import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
import { Assistant } from '../../database/entities/Assistant'
import { Credential } from '../../database/entities/Credential'
import { getUserHome, decryptCredentialData, getAppVersion } from '../../utils'
-import { InternalServerError } from '../../errors/internalServerError'
+import { InternalFlowiseError } from '../../errors/internalFlowiseError'
import { StatusCodes } from 'http-status-codes'
const creatAssistant = async (requestBody: any): Promise => {
try {
const appServer = getRunningExpressApp()
if (!requestBody.details) {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Invalid request body`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Invalid request body`)
}
const assistantDetails = JSON.parse(requestBody.details)
try {
@@ -22,14 +22,14 @@ const creatAssistant = async (requestBody: any): Promise => {
})
if (!credential) {
- throw new InternalServerError(StatusCodes.NOT_FOUND, `Credential ${requestBody.credential} not found`)
+ throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Credential ${requestBody.credential} not found`)
}
// Decrpyt credentialData
const decryptedCredentialData = await decryptCredentialData(credential.encryptedData)
const openAIApiKey = decryptedCredentialData['openAIApiKey']
if (!openAIApiKey) {
- throw new InternalServerError(StatusCodes.NOT_FOUND, `OpenAI ApiKey not found`)
+ throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `OpenAI ApiKey not found`)
}
const openai = new OpenAI({ apiKey: openAIApiKey })
@@ -111,7 +111,7 @@ const creatAssistant = async (requestBody: any): Promise => {
requestBody.details = JSON.stringify(newAssistantDetails)
} catch (error) {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error creating new assistant: ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error creating new assistant: ${error}`)
}
const newAssistant = new Assistant()
Object.assign(newAssistant, requestBody)
@@ -125,7 +125,7 @@ const creatAssistant = async (requestBody: any): Promise => {
})
return dbResponse
} catch (error) {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: assistantsService.creatTool - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: assistantsService.creatTool - ${error}`)
}
}
@@ -136,7 +136,7 @@ const deleteAssistant = async (assistantId: string, isDeleteBoth: any): Promise<
id: assistantId
})
if (!assistant) {
- throw new InternalServerError(StatusCodes.NOT_FOUND, `Assistant ${assistantId} not found`)
+ throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Assistant ${assistantId} not found`)
}
try {
const assistantDetails = JSON.parse(assistant.details)
@@ -145,14 +145,14 @@ const deleteAssistant = async (assistantId: string, isDeleteBoth: any): Promise<
})
if (!credential) {
- throw new InternalServerError(StatusCodes.NOT_FOUND, `Credential ${assistant.credential} not found`)
+ throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Credential ${assistant.credential} not found`)
}
// Decrpyt credentialData
const decryptedCredentialData = await decryptCredentialData(credential.encryptedData)
const openAIApiKey = decryptedCredentialData['openAIApiKey']
if (!openAIApiKey) {
- throw new InternalServerError(StatusCodes.NOT_FOUND, `OpenAI ApiKey not found`)
+ throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `OpenAI ApiKey not found`)
}
const openai = new OpenAI({ apiKey: openAIApiKey })
@@ -163,11 +163,11 @@ const deleteAssistant = async (assistantId: string, isDeleteBoth: any): Promise<
if (error.status === 404 && error.type === 'invalid_request_error') {
return 'OK'
} else {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error deleting assistant: ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error deleting assistant: ${error}`)
}
}
} catch (error) {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: assistantsService.deleteTool - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: assistantsService.deleteTool - ${error}`)
}
}
@@ -177,7 +177,7 @@ const getAllAssistants = async (): Promise => {
const dbResponse = await appServer.AppDataSource.getRepository(Assistant).find()
return dbResponse
} catch (error) {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: assistantsService.getAllAssistants - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: assistantsService.getAllAssistants - ${error}`)
}
}
@@ -188,11 +188,11 @@ const getAssistantById = async (assistantId: string): Promise => {
id: assistantId
})
if (!dbResponse) {
- throw new InternalServerError(StatusCodes.NOT_FOUND, `Assistant ${assistantId} not found`)
+ throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Assistant ${assistantId} not found`)
}
return dbResponse
} catch (error) {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: assistantsService.getAssistantById - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: assistantsService.getAssistantById - ${error}`)
}
}
@@ -204,7 +204,7 @@ const updateAssistant = async (assistantId: string, requestBody: any): Promise endingNodeIds.includes(nd.id))
@@ -53,7 +53,7 @@ const checkIfChatflowIsValidForStreaming = async (chatflowId: string): Promise => {
}
return dbResponse
} catch (error) {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.getAllChatflows - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.getAllChatflows - ${error}`)
}
}
@@ -128,7 +128,7 @@ const getAllChatflows = async (): Promise => {
const dbResponse = await appServer.AppDataSource.getRepository(ChatFlow).find()
return dbResponse
} catch (error) {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.getAllChatflows - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.getAllChatflows - ${error}`)
}
}
@@ -143,11 +143,11 @@ const getChatflowByApiKey = async (apiKeyId: string): Promise => {
.orderBy('cf.name', 'ASC')
.getMany()
if (dbResponse.length < 1) {
- throw new InternalServerError(StatusCodes.NOT_FOUND, `Chatflow not found in the database!`)
+ throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Chatflow not found in the database!`)
}
return dbResponse
} catch (error) {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.getChatflowByApiKey - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.getChatflowByApiKey - ${error}`)
}
}
@@ -158,11 +158,11 @@ const getChatflowById = async (chatflowId: string): Promise => {
id: chatflowId
})
if (!dbResponse) {
- throw new InternalServerError(StatusCodes.NOT_FOUND, `Chatflow ${chatflowId} not found in the database!`)
+ throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Chatflow ${chatflowId} not found in the database!`)
}
return dbResponse
} catch (error) {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.getAllChatflows - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.getAllChatflows - ${error}`)
}
}
@@ -194,7 +194,7 @@ const saveChatflow = async (newChatFlow: ChatFlow): Promise => {
})
return dbResponse
} catch (error) {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.saveChatflow - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.saveChatflow - ${error}`)
}
}
@@ -215,7 +215,7 @@ const updateChatflow = async (chatflow: ChatFlow, updateChatFlow: ChatFlow): Pro
}
return dbResponse
} catch (error) {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.updateChatflow - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.updateChatflow - ${error}`)
}
}
@@ -229,11 +229,11 @@ const getSinglePublicChatflow = async (chatflowId: string): Promise => {
if (dbResponse && dbResponse.isPublic) {
return dbResponse
} else if (dbResponse && !dbResponse.isPublic) {
- throw new InternalServerError(StatusCodes.UNAUTHORIZED, `Unauthorized`)
+ throw new InternalFlowiseError(StatusCodes.UNAUTHORIZED, `Unauthorized`)
}
- throw new InternalServerError(StatusCodes.NOT_FOUND, `Chatflow ${chatflowId} not found`)
+ throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Chatflow ${chatflowId} not found`)
} catch (error) {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.getSinglePublicChatflow - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.getSinglePublicChatflow - ${error}`)
}
}
@@ -246,7 +246,7 @@ const getSinglePublicChatbotConfig = async (chatflowId: string): Promise =>
id: chatflowId
})
if (!dbResponse) {
- throw new InternalServerError(StatusCodes.NOT_FOUND, `Chatflow ${chatflowId} not found`)
+ throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Chatflow ${chatflowId} not found`)
}
const uploadsConfig = await utilGetUploadsConfig(chatflowId)
// even if chatbotConfig is not set but uploads are enabled
@@ -256,12 +256,12 @@ const getSinglePublicChatbotConfig = async (chatflowId: string): Promise =>
const parsedConfig = dbResponse.chatbotConfig ? JSON.parse(dbResponse.chatbotConfig) : {}
return { ...parsedConfig, uploads: uploadsConfig }
} catch (e) {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error parsing Chatbot Config for Chatflow ${chatflowId}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error parsing Chatbot Config for Chatflow ${chatflowId}`)
}
}
return 'OK'
} catch (error) {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.getSinglePublicChatbotConfig - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.getSinglePublicChatbotConfig - ${error}`)
}
}
diff --git a/packages/server/src/services/credentials/index.ts b/packages/server/src/services/credentials/index.ts
index e4ba157d24e..8c012e14382 100644
--- a/packages/server/src/services/credentials/index.ts
+++ b/packages/server/src/services/credentials/index.ts
@@ -3,7 +3,7 @@ import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
import { Credential } from '../../database/entities/Credential'
import { transformToCredentialEntity, decryptCredentialData } from '../../utils'
import { ICredentialReturnResponse } from '../../Interface'
-import { InternalServerError } from '../../errors/internalServerError'
+import { InternalFlowiseError } from '../../errors/internalFlowiseError'
import { StatusCodes } from 'http-status-codes'
const createCredential = async (requestBody: any) => {
@@ -14,7 +14,7 @@ const createCredential = async (requestBody: any) => {
const dbResponse = await appServer.AppDataSource.getRepository(Credential).save(credential)
return dbResponse
} catch (error) {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: credentialsService.createCredential - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: credentialsService.createCredential - ${error}`)
}
}
@@ -24,11 +24,11 @@ const deleteCredentials = async (credentialId: string): Promise => {
const appServer = getRunningExpressApp()
const dbResponse = await appServer.AppDataSource.getRepository(Credential).delete({ id: credentialId })
if (!dbResponse) {
- throw new InternalServerError(StatusCodes.NOT_FOUND, `Credential ${credentialId} not found`)
+ throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Credential ${credentialId} not found`)
}
return dbResponse
} catch (error) {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: credentialsService.deleteCredential - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: credentialsService.deleteCredential - ${error}`)
}
}
@@ -59,7 +59,7 @@ const getAllCredentials = async (paramCredentialName: any) => {
}
return dbResponse
} catch (error) {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: credentialsService.getAllCredentials - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: credentialsService.getAllCredentials - ${error}`)
}
}
@@ -70,7 +70,7 @@ const getCredentialById = async (credentialId: string): Promise => {
id: credentialId
})
if (!credential) {
- throw new InternalServerError(StatusCodes.NOT_FOUND, `Credential ${credentialId} not found`)
+ throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Credential ${credentialId} not found`)
}
// Decrpyt credentialData
const decryptedCredentialData = await decryptCredentialData(
@@ -85,7 +85,7 @@ const getCredentialById = async (credentialId: string): Promise => {
const dbResponse = omit(returnCredential, ['encryptedData'])
return dbResponse
} catch (error) {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: credentialsService.createCredential - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: credentialsService.createCredential - ${error}`)
}
}
@@ -96,14 +96,14 @@ const updateCredential = async (credentialId: string, requestBody: any): Promise
id: credentialId
})
if (!credential) {
- throw new InternalServerError(StatusCodes.NOT_FOUND, `Credential ${credentialId} not found`)
+ throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Credential ${credentialId} not found`)
}
const updateCredential = await transformToCredentialEntity(requestBody)
await appServer.AppDataSource.getRepository(Credential).merge(credential, updateCredential)
const dbResponse = await appServer.AppDataSource.getRepository(Credential).save(credential)
return dbResponse
} catch (error) {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: credentialsService.updateCredential - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: credentialsService.updateCredential - ${error}`)
}
}
diff --git a/packages/server/src/services/fetch-links/index.ts b/packages/server/src/services/fetch-links/index.ts
index b402696d418..f3ff199fdd6 100644
--- a/packages/server/src/services/fetch-links/index.ts
+++ b/packages/server/src/services/fetch-links/index.ts
@@ -1,12 +1,12 @@
import { webCrawl, xmlScrape } from 'flowise-components'
-import { InternalServerError } from '../../errors/internalServerError'
+import { InternalFlowiseError } from '../../errors/internalFlowiseError'
import { StatusCodes } from 'http-status-codes'
const getAllLinks = async (requestUrl: string, relativeLinksMethod: string, queryLimit: string): Promise => {
try {
const url = decodeURIComponent(requestUrl)
if (!relativeLinksMethod) {
- throw new InternalServerError(
+ throw new InternalFlowiseError(
StatusCodes.INTERNAL_SERVER_ERROR,
`Please choose a Relative Links Method in Additional Parameters!`
)
@@ -21,7 +21,7 @@ const getAllLinks = async (requestUrl: string, relativeLinksMethod: string, quer
}
return dbResponse
} catch (error) {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: fetchLinksService.getAllLinks - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: fetchLinksService.getAllLinks - ${error}`)
}
}
diff --git a/packages/server/src/services/flow-configs/index.ts b/packages/server/src/services/flow-configs/index.ts
index cad25359640..a09e7bc7b94 100644
--- a/packages/server/src/services/flow-configs/index.ts
+++ b/packages/server/src/services/flow-configs/index.ts
@@ -2,7 +2,7 @@ import { findAvailableConfigs } from '../../utils'
import { IReactFlowObject } from '../../Interface'
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
import chatflowsService from '../chatflows'
-import { InternalServerError } from '../../errors/internalServerError'
+import { InternalFlowiseError } from '../../errors/internalFlowiseError'
import { StatusCodes } from 'http-status-codes'
const getSingleFlowConfig = async (chatflowId: string): Promise => {
@@ -10,7 +10,7 @@ const getSingleFlowConfig = async (chatflowId: string): Promise => {
const appServer = getRunningExpressApp()
const chatflow = await chatflowsService.getChatflowById(chatflowId)
if (!chatflow) {
- throw new InternalServerError(StatusCodes.NOT_FOUND, `Chatflow ${chatflowId} not found in the database!`)
+ throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Chatflow ${chatflowId} not found in the database!`)
}
const flowData = chatflow.flowData
const parsedFlowData: IReactFlowObject = JSON.parse(flowData)
@@ -18,7 +18,7 @@ const getSingleFlowConfig = async (chatflowId: string): Promise => {
const dbResponse = findAvailableConfigs(nodes, appServer.nodesPool.componentCredentials)
return dbResponse
} catch (error) {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: flowConfigService.getSingleFlowConfig - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: flowConfigService.getSingleFlowConfig - ${error}`)
}
}
diff --git a/packages/server/src/services/nodes/index.ts b/packages/server/src/services/nodes/index.ts
index 0b5fd021bcd..acf631e9952 100644
--- a/packages/server/src/services/nodes/index.ts
+++ b/packages/server/src/services/nodes/index.ts
@@ -4,7 +4,7 @@ import { INodeData } from '../../Interface'
import { INodeOptionsValue, ICommonObject, handleEscapeCharacters } from 'flowise-components'
import { databaseEntities } from '../../utils'
import logger from '../../utils/logger'
-import { InternalServerError } from '../../errors/internalServerError'
+import { InternalFlowiseError } from '../../errors/internalFlowiseError'
import { StatusCodes } from 'http-status-codes'
// Get all component nodes
@@ -18,7 +18,7 @@ const getAllNodes = async () => {
}
return dbResponse
} catch (error) {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: nodesService.getAllNodes - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: nodesService.getAllNodes - ${error}`)
}
}
@@ -30,10 +30,10 @@ const getNodeByName = async (nodeName: string) => {
const dbResponse = appServer.nodesPool.componentNodes[nodeName]
return dbResponse
} else {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Node ${nodeName} not found`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Node ${nodeName} not found`)
}
} catch (error) {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: nodesService.getAllNodes - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: nodesService.getAllNodes - ${error}`)
}
}
@@ -44,20 +44,20 @@ const getSingleNodeIcon = async (nodeName: string) => {
if (Object.prototype.hasOwnProperty.call(appServer.nodesPool.componentNodes, nodeName)) {
const nodeInstance = appServer.nodesPool.componentNodes[nodeName]
if (nodeInstance.icon === undefined) {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Node ${nodeName} icon not found`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Node ${nodeName} icon not found`)
}
if (nodeInstance.icon.endsWith('.svg') || nodeInstance.icon.endsWith('.png') || nodeInstance.icon.endsWith('.jpg')) {
const filepath = nodeInstance.icon
return filepath
} else {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Node ${nodeName} icon is missing icon`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Node ${nodeName} icon is missing icon`)
}
} else {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Node ${nodeName} not found`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Node ${nodeName} not found`)
}
} catch (error) {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: nodesService.getSingleNodeIcon - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: nodesService.getSingleNodeIcon - ${error}`)
}
}
@@ -80,10 +80,10 @@ const getSingleNodeAsyncOptions = async (nodeName: string, requestBody: any): Pr
return []
}
} else {
- throw new InternalServerError(StatusCodes.NOT_FOUND, `Node ${nodeName} not found`)
+ throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Node ${nodeName} not found`)
}
} catch (error) {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: nodesService.getSingleNodeAsyncOptions - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: nodesService.getSingleNodeAsyncOptions - ${error}`)
}
}
@@ -113,13 +113,13 @@ const executeCustomFunction = async (requestBody: any) => {
return dbResponse
} catch (error) {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error running custom function: ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error running custom function: ${error}`)
}
} else {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Node customFunction not found`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Node customFunction not found`)
}
} catch (error) {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: nodesService.executeCustomFunction - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: nodesService.executeCustomFunction - ${error}`)
}
}
diff --git a/packages/server/src/services/openai-assistants/index.ts b/packages/server/src/services/openai-assistants/index.ts
index 71ef35820d8..c0afa2e057d 100644
--- a/packages/server/src/services/openai-assistants/index.ts
+++ b/packages/server/src/services/openai-assistants/index.ts
@@ -2,7 +2,7 @@ import OpenAI from 'openai'
import { decryptCredentialData } from '../../utils'
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
import { Credential } from '../../database/entities/Credential'
-import { InternalServerError } from '../../errors/internalServerError'
+import { InternalFlowiseError } from '../../errors/internalFlowiseError'
import { StatusCodes } from 'http-status-codes'
// ----------------------------------------
@@ -17,20 +17,23 @@ const getAllOpenaiAssistants = async (credentialId: string): Promise => {
id: credentialId
})
if (!credential) {
- throw new InternalServerError(StatusCodes.NOT_FOUND, `Credential ${credentialId} not found in the database!`)
+ throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Credential ${credentialId} not found in the database!`)
}
// Decrpyt credentialData
const decryptedCredentialData = await decryptCredentialData(credential.encryptedData)
const openAIApiKey = decryptedCredentialData['openAIApiKey']
if (!openAIApiKey) {
- throw new InternalServerError(StatusCodes.NOT_FOUND, `OpenAI ApiKey not found`)
+ throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `OpenAI ApiKey not found`)
}
const openai = new OpenAI({ apiKey: openAIApiKey })
const retrievedAssistants = await openai.beta.assistants.list()
const dbResponse = retrievedAssistants.data
return dbResponse
} catch (error) {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: openaiAssistantsService.getAllOpenaiAssistants - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: openaiAssistantsService.getAllOpenaiAssistants - ${error}`
+ )
}
}
@@ -42,13 +45,13 @@ const getSingleOpenaiAssistant = async (credentialId: string, assistantId: strin
id: credentialId
})
if (!credential) {
- throw new InternalServerError(StatusCodes.NOT_FOUND, `Credential ${credentialId} not found in the database!`)
+ throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Credential ${credentialId} not found in the database!`)
}
// Decrpyt credentialData
const decryptedCredentialData = await decryptCredentialData(credential.encryptedData)
const openAIApiKey = decryptedCredentialData['openAIApiKey']
if (!openAIApiKey) {
- throw new InternalServerError(StatusCodes.NOT_FOUND, `OpenAI ApiKey not found`)
+ throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `OpenAI ApiKey not found`)
}
const openai = new OpenAI({ apiKey: openAIApiKey })
@@ -60,7 +63,7 @@ const getSingleOpenaiAssistant = async (credentialId: string, assistantId: strin
}
return dbResponse
} catch (error) {
- throw new InternalServerError(
+ throw new InternalFlowiseError(
StatusCodes.INTERNAL_SERVER_ERROR,
`Error: openaiAssistantsService.getSingleOpenaiAssistant - ${error}`
)
diff --git a/packages/server/src/services/predictions/index.ts b/packages/server/src/services/predictions/index.ts
index 232de30b4d9..0c102bb4fe7 100644
--- a/packages/server/src/services/predictions/index.ts
+++ b/packages/server/src/services/predictions/index.ts
@@ -1,7 +1,7 @@
import { StatusCodes } from 'http-status-codes'
import { utilBuildChatflow } from '../../utils/buildChatflow'
import { Server } from 'socket.io'
-import { InternalServerError } from '../../errors/internalServerError'
+import { InternalFlowiseError } from '../../errors/internalFlowiseError'
import { Request } from 'express'
const buildChatflow = async (fullRequest: Request, ioServer: Server) => {
@@ -9,7 +9,7 @@ const buildChatflow = async (fullRequest: Request, ioServer: Server) => {
const dbResponse = await utilBuildChatflow(fullRequest, ioServer)
return dbResponse
} catch (error) {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, 'Error: predictionsServices.buildChatflow failed!')
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, 'Error: predictionsServices.buildChatflow failed!')
}
}
diff --git a/packages/server/src/services/tools/index.ts b/packages/server/src/services/tools/index.ts
index b9f183d0e20..98bde8e2329 100644
--- a/packages/server/src/services/tools/index.ts
+++ b/packages/server/src/services/tools/index.ts
@@ -1,7 +1,7 @@
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
import { Tool } from '../../database/entities/Tool'
import { getAppVersion } from '../../utils'
-import { InternalServerError } from '../../errors/internalServerError'
+import { InternalFlowiseError } from '../../errors/internalFlowiseError'
import { StatusCodes } from 'http-status-codes'
const creatTool = async (requestBody: any): Promise => {
@@ -18,7 +18,7 @@ const creatTool = async (requestBody: any): Promise => {
})
return dbResponse
} catch (error) {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: toolsService.creatTool - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: toolsService.creatTool - ${error}`)
}
}
@@ -30,7 +30,7 @@ const deleteTool = async (toolId: string): Promise => {
})
return dbResponse
} catch (error) {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: toolsService.deleteTool - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: toolsService.deleteTool - ${error}`)
}
}
@@ -40,7 +40,7 @@ const getAllTools = async (): Promise => {
const dbResponse = await appServer.AppDataSource.getRepository(Tool).find()
return dbResponse
} catch (error) {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: toolsService.getAllTools - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: toolsService.getAllTools - ${error}`)
}
}
@@ -51,11 +51,11 @@ const getToolById = async (toolId: string): Promise => {
id: toolId
})
if (!dbResponse) {
- throw new InternalServerError(StatusCodes.NOT_FOUND, `Tool ${toolId} not found`)
+ throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Tool ${toolId} not found`)
}
return dbResponse
} catch (error) {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: toolsService.getToolById - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: toolsService.getToolById - ${error}`)
}
}
@@ -66,7 +66,7 @@ const updateTool = async (toolId: string, toolBody: any): Promise => {
id: toolId
})
if (!tool) {
- throw new InternalServerError(StatusCodes.NOT_FOUND, `Tool ${toolId} not found`)
+ throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Tool ${toolId} not found`)
}
const updateTool = new Tool()
Object.assign(updateTool, toolBody)
@@ -74,7 +74,7 @@ const updateTool = async (toolId: string, toolBody: any): Promise => {
const dbResponse = await appServer.AppDataSource.getRepository(Tool).save(tool)
return dbResponse
} catch (error) {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: toolsService.getToolById - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: toolsService.getToolById - ${error}`)
}
}
diff --git a/packages/server/src/services/versions/index.ts b/packages/server/src/services/versions/index.ts
index 3cd40b4bb8c..00a97ee181e 100644
--- a/packages/server/src/services/versions/index.ts
+++ b/packages/server/src/services/versions/index.ts
@@ -1,6 +1,6 @@
import path from 'path'
import * as fs from 'fs'
-import { InternalServerError } from '../../errors/internalServerError'
+import { InternalFlowiseError } from '../../errors/internalFlowiseError'
import { StatusCodes } from 'http-status-codes'
const getVersion = async () => {
@@ -22,7 +22,7 @@ const getVersion = async () => {
}
const packagejsonPath = getPackageJsonPath()
if (!packagejsonPath) {
- throw new InternalServerError(StatusCodes.NOT_FOUND, `Version not found`)
+ throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Version not found`)
}
try {
const content = await fs.promises.readFile(packagejsonPath, 'utf8')
@@ -31,10 +31,10 @@ const getVersion = async () => {
version: parsedContent.version
}
} catch (error) {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Version not found: ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Version not found: ${error}`)
}
} catch (error) {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: versionService.getVersion - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: versionService.getVersion - ${error}`)
}
}
diff --git a/packages/server/src/utils/buildChatflow.ts b/packages/server/src/utils/buildChatflow.ts
index 4a36d8f3b45..16cdd88cb8a 100644
--- a/packages/server/src/utils/buildChatflow.ts
+++ b/packages/server/src/utils/buildChatflow.ts
@@ -3,7 +3,7 @@ import { IFileUpload, getStoragePath, convertSpeechToText, ICommonObject } from
import { StatusCodes } from 'http-status-codes'
import { IncomingInput, IMessage, INodeData, IReactFlowObject, IReactFlowNode, IDepthQueue, chatType, IChatMessage } from '../Interface'
import path from 'path'
-import { InternalServerError } from '../errors/internalServerError'
+import { InternalFlowiseError } from '../errors/internalFlowiseError'
import { ChatFlow } from '../database/entities/ChatFlow'
import { Server } from 'socket.io'
import { getRunningExpressApp } from '../utils/getRunningExpressApp'
@@ -48,7 +48,7 @@ export const utilBuildChatflow = async (req: Request, socketIO?: Server, isInter
id: chatflowid
})
if (!chatflow) {
- throw new InternalServerError(StatusCodes.NOT_FOUND, `Chatflow ${chatflowid} not found`)
+ throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Chatflow ${chatflowid} not found`)
}
const chatId = incomingInput.chatId ?? incomingInput.overrideConfig?.sessionId ?? uuidv4()
@@ -57,7 +57,7 @@ export const utilBuildChatflow = async (req: Request, socketIO?: Server, isInter
if (!isInternal) {
const isKeyValidated = await utilValidateKey(req, chatflow)
if (!isKeyValidated) {
- throw new InternalServerError(StatusCodes.UNAUTHORIZED, `Unauthorized`)
+ throw new InternalFlowiseError(StatusCodes.UNAUTHORIZED, `Unauthorized`)
}
}
@@ -182,7 +182,7 @@ export const utilBuildChatflow = async (req: Request, socketIO?: Server, isInter
const directedGraph = graph
const endingNodeIds = getEndingNodes(nodeDependencies, directedGraph)
if (!endingNodeIds.length) {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Ending nodes not found`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Ending nodes not found`)
}
const endingNodes = nodes.filter((nd) => endingNodeIds.includes(nd.id))
@@ -192,7 +192,7 @@ export const utilBuildChatflow = async (req: Request, socketIO?: Server, isInter
for (const endingNode of endingNodes) {
const endingNodeData = endingNode.data
if (!endingNodeData) {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Ending node ${endingNode.id} data not found`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Ending node ${endingNode.id} data not found`)
}
const isEndingNode = endingNodeData?.outputs?.output === 'EndingNode'
@@ -204,7 +204,7 @@ export const utilBuildChatflow = async (req: Request, socketIO?: Server, isInter
endingNodeData.category !== 'Agents' &&
endingNodeData.category !== 'Engine'
) {
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, `Ending node must be either a Chain or Agent`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Ending node must be either a Chain or Agent`)
}
if (
@@ -212,7 +212,7 @@ export const utilBuildChatflow = async (req: Request, socketIO?: Server, isInter
Object.keys(endingNodeData.outputs).length &&
!Object.values(endingNodeData.outputs ?? {}).includes(endingNodeData.name)
) {
- throw new InternalServerError(
+ throw new InternalFlowiseError(
StatusCodes.INTERNAL_SERVER_ERROR,
`Output of ${endingNodeData.label} (${endingNodeData.id}) must be ${endingNodeData.label}, can't be an Output Prediction`
)
@@ -291,7 +291,7 @@ export const utilBuildChatflow = async (req: Request, socketIO?: Server, isInter
? reactFlowNodes.find((node: IReactFlowNode) => endingNodeIds[0] === node.id)
: reactFlowNodes[reactFlowNodes.length - 1]
if (!nodeToExecute) {
- throw new InternalServerError(StatusCodes.NOT_FOUND, `Node not found`)
+ throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Node not found`)
}
if (incomingInput.overrideConfig) {
@@ -393,6 +393,6 @@ export const utilBuildChatflow = async (req: Request, socketIO?: Server, isInter
return result
} catch (e: any) {
logger.error('[server]: Error:', e)
- throw new InternalServerError(StatusCodes.INTERNAL_SERVER_ERROR, e.message)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, e.message)
}
}
From ee42658beb573b791ced1ad22cd43249989a0108 Mon Sep 17 00:00:00 2001
From: ocflowiseai <154992625+ocflowiseai@users.noreply.github.com>
Date: Mon, 8 Apr 2024 10:42:38 +0200
Subject: [PATCH 14/18] Use InternalFlowiseError in services
---
.../server/src/controllers/stats/index.ts | 4 ++-
.../server/src/controllers/tools/index.ts | 12 ++++---
.../server/src/controllers/variables/index.ts | 16 +++++++---
packages/server/src/services/apikey/index.ts | 10 +++---
.../src/services/chat-messages/index.ts | 13 +++++---
.../services/components-credentials/index.ts | 31 ++++++++++++++-----
.../server/src/services/feedback/index.ts | 14 +++++++--
.../server/src/services/load-prompts/index.ts | 4 ++-
.../server/src/services/marketplaces/index.ts | 4 ++-
.../server/src/services/node-configs/index.ts | 4 ++-
packages/server/src/services/stats/index.ts | 4 ++-
.../src/services/upsert-history/index.ts | 6 ++--
.../server/src/services/variables/index.ts | 12 ++++---
packages/server/src/services/vectors/index.ts | 4 ++-
.../server/src/utils/addChatflowsCount.ts | 4 ++-
15 files changed, 99 insertions(+), 43 deletions(-)
diff --git a/packages/server/src/controllers/stats/index.ts b/packages/server/src/controllers/stats/index.ts
index fc60d66efa6..a8ff0a272fd 100644
--- a/packages/server/src/controllers/stats/index.ts
+++ b/packages/server/src/controllers/stats/index.ts
@@ -1,11 +1,13 @@
import { Request, Response, NextFunction } from 'express'
import statsService from '../../services/stats'
import { chatType } from '../../Interface'
+import { InternalFlowiseError } from '../../errors/internalFlowiseError'
+import { StatusCodes } from 'http-status-codes'
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!`)
+ 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
diff --git a/packages/server/src/controllers/tools/index.ts b/packages/server/src/controllers/tools/index.ts
index f1376795a20..b45eeba20a2 100644
--- a/packages/server/src/controllers/tools/index.ts
+++ b/packages/server/src/controllers/tools/index.ts
@@ -1,10 +1,12 @@
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) => {
try {
if (typeof req.body === 'undefined' || req.body === '') {
- throw new Error(`Error: toolsController.creatTool - body not provided!`)
+ throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: toolsController.creatTool - body not provided!`)
}
const apiResponse = await toolsService.creatTool(req.body)
return res.json(apiResponse)
@@ -16,7 +18,7 @@ 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!`)
+ throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: toolsController.deleteTool - id not provided!`)
}
const apiResponse = await toolsService.deleteTool(req.params.id)
return res.json(apiResponse)
@@ -37,7 +39,7 @@ 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!`)
+ throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: toolsController.getToolById - id not provided!`)
}
const apiResponse = await toolsService.getToolById(req.params.id)
return res.json(apiResponse)
@@ -49,10 +51,10 @@ 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!`)
+ 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!`)
+ throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: toolsController.deleteTool - body not provided!`)
}
const apiResponse = await toolsService.updateTool(req.params.id, req.body)
return res.json(apiResponse)
diff --git a/packages/server/src/controllers/variables/index.ts b/packages/server/src/controllers/variables/index.ts
index 4dfd7492a5d..67eaa8f27e4 100644
--- a/packages/server/src/controllers/variables/index.ts
+++ b/packages/server/src/controllers/variables/index.ts
@@ -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()
@@ -20,7 +25,7 @@ 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!')
+ throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, 'Error: variablesController.deleteVariable - id not provided!')
}
const apiResponse = await variablesService.deleteVariable(req.params.id)
return res.json(apiResponse)
@@ -41,10 +46,13 @@ 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!')
+ 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) {
diff --git a/packages/server/src/services/apikey/index.ts b/packages/server/src/services/apikey/index.ts
index 988b42ec2a9..5fa2d89d39d 100644
--- a/packages/server/src/services/apikey/index.ts
+++ b/packages/server/src/services/apikey/index.ts
@@ -10,7 +10,7 @@ const getAllApiKeys = async () => {
const dbResponse = await addChatflowsCount(keys)
return dbResponse
} catch (error) {
- throw new Error(`Error: apikeyService.getAllApiKeys - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: apikeyService.getAllApiKeys - ${error}`)
}
}
@@ -20,7 +20,7 @@ const createApiKey = async (keyName: string) => {
const dbResponse = await addChatflowsCount(keys)
return dbResponse
} catch (error) {
- throw new Error(`Error: apikeyService.createApiKey - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: apikeyService.createApiKey - ${error}`)
}
}
@@ -31,7 +31,7 @@ const updateApiKey = async (id: string, keyName: string) => {
const dbResponse = await addChatflowsCount(keys)
return dbResponse
} catch (error) {
- throw new Error(`Error: apikeyService.updateApiKey - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: apikeyService.updateApiKey - ${error}`)
}
}
@@ -41,7 +41,7 @@ const deleteApiKey = async (id: string) => {
const dbResponse = await addChatflowsCount(keys)
return dbResponse
} catch (error) {
- throw new Error(`Error: apikeyService.deleteApiKey - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: apikeyService.deleteApiKey - ${error}`)
}
}
@@ -54,7 +54,7 @@ const verifyApiKey = async (paramApiKey: string): Promise => {
const dbResponse = 'OK'
return dbResponse
} catch (error) {
- throw new Error(`Error: apikeyService.verifyApiKey - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: apikeyService.verifyApiKey - ${error}`)
}
}
diff --git a/packages/server/src/services/chat-messages/index.ts b/packages/server/src/services/chat-messages/index.ts
index 8b87f9db094..d30f3facb21 100644
--- a/packages/server/src/services/chat-messages/index.ts
+++ b/packages/server/src/services/chat-messages/index.ts
@@ -9,6 +9,8 @@ import { getStoragePath } from 'flowise-components'
import { deleteFolderRecursive } from '../../utils'
import logger from '../../utils/logger'
import { ChatMessage } from '../../database/entities/ChatMessage'
+import { InternalFlowiseError } from '../../errors/internalFlowiseError'
+import { StatusCodes } from 'http-status-codes'
// Add chatmessages for chatflowid
const createChatMessage = async (chatMessage: Partial) => {
@@ -16,7 +18,7 @@ const createChatMessage = async (chatMessage: Partial) => {
const dbResponse = await utilAddChatMessage(chatMessage)
return dbResponse
} catch (error) {
- throw new Error(`Error: chatMessagesService.createChatMessage - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatMessagesService.createChatMessage - ${error}`)
}
}
@@ -48,7 +50,7 @@ const getAllChatMessages = async (
)
return dbResponse
} catch (error) {
- throw new Error(`Error: chatMessagesService.getAllChatMessages - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatMessagesService.getAllChatMessages - ${error}`)
}
}
@@ -80,7 +82,10 @@ const getAllInternalChatMessages = async (
)
return dbResponse
} catch (error) {
- throw new Error(`Error: chatMessagesService.getAllInternalChatMessages - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: chatMessagesService.getAllInternalChatMessages - ${error}`
+ )
}
}
@@ -104,7 +109,7 @@ const removeAllChatMessages = async (chatId: string, chatflowid: string, deleteO
const dbResponse = await appServer.AppDataSource.getRepository(ChatMessage).delete(deleteOptions)
return dbResponse
} catch (error) {
- throw new Error(`Error: chatMessagesService.removeAllChatMessages - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatMessagesService.removeAllChatMessages - ${error}`)
}
}
diff --git a/packages/server/src/services/components-credentials/index.ts b/packages/server/src/services/components-credentials/index.ts
index bbc4128a2f2..f851b1622a9 100644
--- a/packages/server/src/services/components-credentials/index.ts
+++ b/packages/server/src/services/components-credentials/index.ts
@@ -1,5 +1,7 @@
import { cloneDeep } from 'lodash'
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
+import { InternalFlowiseError } from '../../errors/internalFlowiseError'
+import { StatusCodes } from 'http-status-codes'
// Get all component credentials
const getAllComponentsCredentials = async (): Promise => {
@@ -12,7 +14,10 @@ const getAllComponentsCredentials = async (): Promise => {
}
return dbResponse
} catch (error) {
- throw new Error(`Error: componentsCredentialsService.getAllComponentsCredentials - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: componentsCredentialsService.getAllComponentsCredentials - ${error}`
+ )
}
}
@@ -23,7 +28,8 @@ const getComponentByName = async (credentialName: string) => {
if (Object.prototype.hasOwnProperty.call(appServer.nodesPool.componentCredentials, credentialName)) {
return appServer.nodesPool.componentCredentials[credentialName]
} else {
- throw new Error(
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
`Error: componentsCredentialsService.getSingleComponentsCredential - Credential ${credentialName} not found`
)
}
@@ -33,13 +39,19 @@ const getComponentByName = async (credentialName: string) => {
if (Object.prototype.hasOwnProperty.call(appServer.nodesPool.componentCredentials, name)) {
dbResponse.push(appServer.nodesPool.componentCredentials[name])
} else {
- throw new Error(`Error: componentsCredentialsService.getSingleComponentsCredential - Credential ${name} not found`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: componentsCredentialsService.getSingleComponentsCredential - Credential ${name} not found`
+ )
}
}
return dbResponse
}
} catch (error) {
- throw new Error(`Error: componentsCredentialsService.getSingleComponentsCredential - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: componentsCredentialsService.getSingleComponentsCredential - ${error}`
+ )
}
}
@@ -50,20 +62,23 @@ const getSingleComponentsCredentialIcon = async (credentialName: string) => {
if (Object.prototype.hasOwnProperty.call(appServer.nodesPool.componentCredentials, credentialName)) {
const credInstance = appServer.nodesPool.componentCredentials[credentialName]
if (credInstance.icon === undefined) {
- throw new Error(`Credential ${credentialName} icon not found`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Credential ${credentialName} icon not found`)
}
if (credInstance.icon.endsWith('.svg') || credInstance.icon.endsWith('.png') || credInstance.icon.endsWith('.jpg')) {
const filepath = credInstance.icon
return filepath
} else {
- throw new Error(`Credential ${credentialName} icon is missing icon`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Credential ${credentialName} icon is missing icon`)
}
} else {
- throw new Error(`Credential ${credentialName} not found`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Credential ${credentialName} not found`)
}
} catch (error) {
- throw new Error(`Error: componentsCredentialsService.getSingleComponentsCredentialIcon - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: componentsCredentialsService.getSingleComponentsCredentialIcon - ${error}`
+ )
}
}
diff --git a/packages/server/src/services/feedback/index.ts b/packages/server/src/services/feedback/index.ts
index 9084be613dd..e74788609ab 100644
--- a/packages/server/src/services/feedback/index.ts
+++ b/packages/server/src/services/feedback/index.ts
@@ -2,6 +2,8 @@ import { utilGetChatMessageFeedback } from '../../utils/getChatMessageFeedback'
import { utilAddChatMessageFeedback } from '../../utils/addChatMessageFeedback'
import { utilUpdateChatMessageFeedback } from '../../utils/updateChatMessageFeedback'
import { IChatMessageFeedback } from '../../Interface'
+import { InternalFlowiseError } from '../../errors/internalFlowiseError'
+import { StatusCodes } from 'http-status-codes'
// Get all chatmessage feedback from chatflowid
const getAllChatMessageFeedback = async (
@@ -15,7 +17,7 @@ const getAllChatMessageFeedback = async (
const dbResponse = await utilGetChatMessageFeedback(chatflowid, chatId, sortOrder, startDate, endDate)
return dbResponse
} catch (error) {
- throw new Error(`Error: feedbackService.getAllChatMessageFeedback - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: feedbackService.getAllChatMessageFeedback - ${error}`)
}
}
@@ -25,7 +27,10 @@ const createChatMessageFeedbackForChatflow = async (requestBody: Partial => {
try {
@@ -13,7 +15,7 @@ const createPrompt = async (promptName: string): Promise => {
}
return dbResponse
} catch (error) {
- throw new Error(`Error: loadPromptsService.createPrompt - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: loadPromptsService.createPrompt - ${error}`)
}
}
diff --git a/packages/server/src/services/marketplaces/index.ts b/packages/server/src/services/marketplaces/index.ts
index 218452dd3df..b37f8ce93cd 100644
--- a/packages/server/src/services/marketplaces/index.ts
+++ b/packages/server/src/services/marketplaces/index.ts
@@ -1,5 +1,7 @@
import path from 'path'
import * as fs from 'fs'
+import { InternalFlowiseError } from '../../errors/internalFlowiseError'
+import { StatusCodes } from 'http-status-codes'
// Get all templates for marketplaces
const getAllTemplates = async () => {
@@ -49,7 +51,7 @@ const getAllTemplates = async () => {
const dbResponse = sortedTemplates
return dbResponse
} catch (error) {
- throw new Error(`Error: marketplacesService.getAllTemplates - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: marketplacesService.getAllTemplates - ${error}`)
}
}
diff --git a/packages/server/src/services/node-configs/index.ts b/packages/server/src/services/node-configs/index.ts
index 7eb523e81e8..8005f55f86f 100644
--- a/packages/server/src/services/node-configs/index.ts
+++ b/packages/server/src/services/node-configs/index.ts
@@ -1,6 +1,8 @@
import { findAvailableConfigs } from '../../utils'
import { IReactFlowNode } from '../../Interface'
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
+import { InternalFlowiseError } from '../../errors/internalFlowiseError'
+import { StatusCodes } from 'http-status-codes'
const getAllNodeConfigs = async (requestBody: any) => {
try {
@@ -9,7 +11,7 @@ const getAllNodeConfigs = async (requestBody: any) => {
const dbResponse = findAvailableConfigs(nodes, appServer.nodesPool.componentCredentials)
return dbResponse
} catch (error) {
- throw new Error(`Error: nodeConfigsService.getAllNodeConfigs - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: nodeConfigsService.getAllNodeConfigs - ${error}`)
}
}
diff --git a/packages/server/src/services/stats/index.ts b/packages/server/src/services/stats/index.ts
index 2f2448a1e50..5deae55ee83 100644
--- a/packages/server/src/services/stats/index.ts
+++ b/packages/server/src/services/stats/index.ts
@@ -2,6 +2,8 @@ import { chatType } from '../../Interface'
import { ChatMessage } from '../../database/entities/ChatMessage'
import { utilGetChatMessage } from '../../utils/getChatMessage'
import { ChatMessageFeedback } from '../../database/entities/ChatMessageFeedback'
+import { InternalFlowiseError } from '../../errors/internalFlowiseError'
+import { StatusCodes } from 'http-status-codes'
// get stats for showing in chatflow
const getChatflowStats = async (
@@ -36,7 +38,7 @@ const getChatflowStats = async (
return dbResponse
} catch (error) {
- throw new Error(`Error: statsService.getChatflowStats - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: statsService.getChatflowStats - ${error}`)
}
}
diff --git a/packages/server/src/services/upsert-history/index.ts b/packages/server/src/services/upsert-history/index.ts
index 96d9d82db69..a3920440a7e 100644
--- a/packages/server/src/services/upsert-history/index.ts
+++ b/packages/server/src/services/upsert-history/index.ts
@@ -1,6 +1,8 @@
import { MoreThanOrEqual, LessThanOrEqual } from 'typeorm'
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
import { UpsertHistory } from '../../database/entities/UpsertHistory'
+import { InternalFlowiseError } from '../../errors/internalFlowiseError'
+import { StatusCodes } from 'http-status-codes'
const getAllUpsertHistory = async (
sortOrder: string | undefined,
@@ -46,7 +48,7 @@ const getAllUpsertHistory = async (
return upsertHistory
} catch (error) {
- throw new Error(`Error: upsertHistoryServices.getAllUpsertHistory - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: upsertHistoryServices.getAllUpsertHistory - ${error}`)
}
}
@@ -56,7 +58,7 @@ const patchDeleteUpsertHistory = async (ids: string[] = []): Promise => {
const dbResponse = await appServer.AppDataSource.getRepository(UpsertHistory).delete(ids)
return dbResponse
} catch (error) {
- throw new Error(`Error: upsertHistoryServices.patchUpsertHistory - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: upsertHistoryServices.patchUpsertHistory - ${error}`)
}
}
diff --git a/packages/server/src/services/variables/index.ts b/packages/server/src/services/variables/index.ts
index 37e1c073824..60ea4c6120e 100644
--- a/packages/server/src/services/variables/index.ts
+++ b/packages/server/src/services/variables/index.ts
@@ -1,5 +1,7 @@
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
import { Variable } from '../../database/entities/Variable'
+import { InternalFlowiseError } from '../../errors/internalFlowiseError'
+import { StatusCodes } from 'http-status-codes'
const createVariable = async (newVariable: Variable) => {
try {
@@ -8,7 +10,7 @@ const createVariable = async (newVariable: Variable) => {
const dbResponse = await appServer.AppDataSource.getRepository(Variable).save(variable)
return dbResponse
} catch (error) {
- throw new Error(`Error: variablesServices.createVariable - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: variablesServices.createVariable - ${error}`)
}
}
@@ -18,7 +20,7 @@ const deleteVariable = async (variableId: string): Promise => {
const dbResponse = await appServer.AppDataSource.getRepository(Variable).delete({ id: variableId })
return dbResponse
} catch (error) {
- throw new Error(`Error: variablesServices.deleteVariable - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: variablesServices.deleteVariable - ${error}`)
}
}
@@ -28,7 +30,7 @@ const getAllVariables = async () => {
const dbResponse = await appServer.AppDataSource.getRepository(Variable).find()
return dbResponse
} catch (error) {
- throw new Error(`Error: variablesServices.getAllVariables - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: variablesServices.getAllVariables - ${error}`)
}
}
@@ -40,7 +42,7 @@ const getVariableById = async (variableId: string) => {
})
return dbResponse
} catch (error) {
- throw new Error(`Error: variablesServices.getVariableById - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: variablesServices.getVariableById - ${error}`)
}
}
@@ -51,7 +53,7 @@ const updateVariable = async (variable: Variable, updatedVariable: Variable) =>
const dbResponse = await appServer.AppDataSource.getRepository(Variable).save(tmpUpdatedVariable)
return dbResponse
} catch (error) {
- throw new Error(`Error: variablesServices.updateVariable - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: variablesServices.updateVariable - ${error}`)
}
}
diff --git a/packages/server/src/services/vectors/index.ts b/packages/server/src/services/vectors/index.ts
index 7c55a510d45..c16f9805fbe 100644
--- a/packages/server/src/services/vectors/index.ts
+++ b/packages/server/src/services/vectors/index.ts
@@ -1,11 +1,13 @@
import { Request, Response } from 'express'
import { upsertVector } from '../../utils/upsertVector'
+import { InternalFlowiseError } from '../../errors/internalFlowiseError'
+import { StatusCodes } from 'http-status-codes'
const upsertVectorMiddleware = async (req: Request, res: Response, isInternal: boolean = false) => {
try {
await upsertVector(req, res, isInternal)
} catch (error) {
- throw new Error(`Error: vectorsService.getRateLimiter - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: vectorsService.getRateLimiter - ${error}`)
}
}
diff --git a/packages/server/src/utils/addChatflowsCount.ts b/packages/server/src/utils/addChatflowsCount.ts
index c0ee664a4d2..8c3464cf85c 100644
--- a/packages/server/src/utils/addChatflowsCount.ts
+++ b/packages/server/src/utils/addChatflowsCount.ts
@@ -1,4 +1,6 @@
+import { StatusCodes } from 'http-status-codes'
import { ChatFlow } from '../database/entities/ChatFlow'
+import { InternalFlowiseError } from '../errors/internalFlowiseError'
import { getRunningExpressApp } from '../utils/getRunningExpressApp'
export const addChatflowsCount = async (keys: any) => {
@@ -28,6 +30,6 @@ export const addChatflowsCount = async (keys: any) => {
}
return tmpResult
} catch (error) {
- throw new Error(`Error: addChatflowsCount - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: addChatflowsCount - ${error}`)
}
}
From 1d7bb662138ef1313bc408f70d366f02ba7ef86e Mon Sep 17 00:00:00 2001
From: ocflowiseai <154992625+ocflowiseai@users.noreply.github.com>
Date: Mon, 8 Apr 2024 11:09:10 +0200
Subject: [PATCH 15/18] Catch routes without preconditioned parameters
---
packages/server/src/routes/apikey/index.ts | 4 ++--
packages/server/src/routes/assistants/index.ts | 6 +++---
packages/server/src/routes/chat-messages/index.ts | 6 +++---
packages/server/src/routes/chatflows-streaming/index.ts | 2 +-
packages/server/src/routes/chatflows-uploads/index.ts | 2 +-
packages/server/src/routes/chatflows/index.ts | 8 ++++----
.../src/routes/components-credentials-icon/index.ts | 2 +-
.../server/src/routes/components-credentials/index.ts | 2 +-
packages/server/src/routes/credentials/index.ts | 6 +++---
packages/server/src/routes/feedback/index.ts | 6 +++---
packages/server/src/routes/flow-config/index.ts | 2 +-
.../server/src/routes/internal-chat-messages/index.ts | 2 +-
packages/server/src/routes/internal-predictions/index.ts | 2 +-
packages/server/src/routes/node-icons/index.ts | 2 +-
packages/server/src/routes/node-load-methods/index.ts | 2 +-
packages/server/src/routes/nodes/index.ts | 2 +-
packages/server/src/routes/openai-assistants/index.ts | 2 +-
packages/server/src/routes/predictions/index.ts | 2 +-
packages/server/src/routes/public-chatbots/index.ts | 2 +-
packages/server/src/routes/public-chatflows/index.ts | 2 +-
packages/server/src/routes/stats/index.ts | 2 +-
packages/server/src/routes/tools/index.ts | 6 +++---
packages/server/src/routes/upsert-history/index.ts | 2 +-
packages/server/src/routes/variables/index.ts | 4 ++--
packages/server/src/routes/vectors/index.ts | 9 +++++++--
packages/server/src/routes/verify/index.ts | 2 +-
26 files changed, 47 insertions(+), 42 deletions(-)
diff --git a/packages/server/src/routes/apikey/index.ts b/packages/server/src/routes/apikey/index.ts
index e82924d874d..566d12e8bf1 100644
--- a/packages/server/src/routes/apikey/index.ts
+++ b/packages/server/src/routes/apikey/index.ts
@@ -9,9 +9,9 @@ router.post('/', apikeyController.createApiKey)
router.get('/', apikeyController.getAllApiKeys)
// UPDATE
-router.put('/:id', apikeyController.updateApiKey)
+router.put(['/', '/:id'], apikeyController.updateApiKey)
// DELETE
-router.delete('/:id', apikeyController.deleteApiKey)
+router.delete(['/', '/:id'], apikeyController.deleteApiKey)
export default router
diff --git a/packages/server/src/routes/assistants/index.ts b/packages/server/src/routes/assistants/index.ts
index 494f8f9de2c..2ca1254b8ec 100644
--- a/packages/server/src/routes/assistants/index.ts
+++ b/packages/server/src/routes/assistants/index.ts
@@ -8,12 +8,12 @@ router.post('/', assistantsController.creatAssistant)
// READ
router.get('/', assistantsController.getAllAssistants)
-router.get('/:id', assistantsController.getAssistantById)
+router.get(['/', '/:id'], assistantsController.getAssistantById)
// UPDATE
-router.put('/:id', assistantsController.updateAssistant)
+router.put(['/', '/:id'], assistantsController.updateAssistant)
// DELETE
-router.delete('/:id', assistantsController.deleteAssistant)
+router.delete(['/', '/:id'], assistantsController.deleteAssistant)
export default router
diff --git a/packages/server/src/routes/chat-messages/index.ts b/packages/server/src/routes/chat-messages/index.ts
index dbb3e9f12a5..64dacb13005 100644
--- a/packages/server/src/routes/chat-messages/index.ts
+++ b/packages/server/src/routes/chat-messages/index.ts
@@ -3,14 +3,14 @@ import chatMessageController from '../../controllers/chat-messages'
const router = express.Router()
// CREATE
-router.post('/:id', chatMessageController.createChatMessage)
+router.post(['/', '/:id'], chatMessageController.createChatMessage)
// READ
-router.get('/:id', chatMessageController.getAllChatMessages)
+router.get(['/', '/:id'], chatMessageController.getAllChatMessages)
// UPDATE
// DELETE
-router.delete('/:id', chatMessageController.removeAllChatMessages)
+router.delete(['/', '/:id'], chatMessageController.removeAllChatMessages)
export default router
diff --git a/packages/server/src/routes/chatflows-streaming/index.ts b/packages/server/src/routes/chatflows-streaming/index.ts
index 34ca4e0c7e1..cc8dc257c1f 100644
--- a/packages/server/src/routes/chatflows-streaming/index.ts
+++ b/packages/server/src/routes/chatflows-streaming/index.ts
@@ -4,6 +4,6 @@ import chatflowsController from '../../controllers/chatflows'
const router = express.Router()
// READ
-router.get('/:id', chatflowsController.checkIfChatflowIsValidForStreaming)
+router.get(['/', '/:id'], chatflowsController.checkIfChatflowIsValidForStreaming)
export default router
diff --git a/packages/server/src/routes/chatflows-uploads/index.ts b/packages/server/src/routes/chatflows-uploads/index.ts
index b3b3ff03ded..591718c2b89 100644
--- a/packages/server/src/routes/chatflows-uploads/index.ts
+++ b/packages/server/src/routes/chatflows-uploads/index.ts
@@ -4,6 +4,6 @@ import chatflowsController from '../../controllers/chatflows'
const router = express.Router()
// READ
-router.get('/:id', chatflowsController.checkIfChatflowIsValidForUploads)
+router.get(['/', '/:id'], chatflowsController.checkIfChatflowIsValidForUploads)
export default router
diff --git a/packages/server/src/routes/chatflows/index.ts b/packages/server/src/routes/chatflows/index.ts
index 8cd3fcc01d1..8fb457fd3e6 100644
--- a/packages/server/src/routes/chatflows/index.ts
+++ b/packages/server/src/routes/chatflows/index.ts
@@ -7,13 +7,13 @@ router.post('/', chatflowsController.saveChatflow)
// READ
router.get('/', chatflowsController.getAllChatflows)
-router.get('/:id', chatflowsController.getChatflowById)
-router.get('/apikey/:apikey', chatflowsController.getChatflowByApiKey)
+router.get(['/', '/:id'], chatflowsController.getChatflowById)
+router.get(['/apikey/', '/apikey/:apikey'], chatflowsController.getChatflowByApiKey)
// UPDATE
-router.put('/:id', chatflowsController.updateChatflow)
+router.put(['/', '/:id'], chatflowsController.updateChatflow)
// DELETE
-router.delete('/:id', chatflowsController.deleteChatflow)
+router.delete(['/', '/:id'], chatflowsController.deleteChatflow)
export default router
diff --git a/packages/server/src/routes/components-credentials-icon/index.ts b/packages/server/src/routes/components-credentials-icon/index.ts
index 364a87ba39e..50d22134b2e 100644
--- a/packages/server/src/routes/components-credentials-icon/index.ts
+++ b/packages/server/src/routes/components-credentials-icon/index.ts
@@ -5,7 +5,7 @@ const router = express.Router()
// CREATE
// READ
-router.get('/:name', componentsCredentialsController.getSingleComponentsCredentialIcon)
+router.get(['/', '/:name'], componentsCredentialsController.getSingleComponentsCredentialIcon)
// UPDATE
diff --git a/packages/server/src/routes/components-credentials/index.ts b/packages/server/src/routes/components-credentials/index.ts
index 2f7b23646e0..16aff2ff2b1 100644
--- a/packages/server/src/routes/components-credentials/index.ts
+++ b/packages/server/src/routes/components-credentials/index.ts
@@ -4,6 +4,6 @@ const router = express.Router()
// READ
router.get('/', componentsCredentialsController.getAllComponentsCredentials)
-router.get('/:name', componentsCredentialsController.getComponentByName)
+router.get(['/', '/:name'], componentsCredentialsController.getComponentByName)
export default router
diff --git a/packages/server/src/routes/credentials/index.ts b/packages/server/src/routes/credentials/index.ts
index 0229798bf00..9f118b49d12 100644
--- a/packages/server/src/routes/credentials/index.ts
+++ b/packages/server/src/routes/credentials/index.ts
@@ -7,12 +7,12 @@ router.post('/', credentialsController.createCredential)
// READ
router.get('/', credentialsController.getAllCredentials)
-router.get('/:id', credentialsController.getCredentialById)
+router.get(['/', '/:id'], credentialsController.getCredentialById)
// UPDATE
-router.put('/:id', credentialsController.updateCredential)
+router.put(['/', '/:id'], credentialsController.updateCredential)
// DELETE
-router.delete('/:id', credentialsController.deleteCredentials)
+router.delete(['/', '/:id'], credentialsController.deleteCredentials)
export default router
diff --git a/packages/server/src/routes/feedback/index.ts b/packages/server/src/routes/feedback/index.ts
index 3502a9fb377..bcec7c74ad3 100644
--- a/packages/server/src/routes/feedback/index.ts
+++ b/packages/server/src/routes/feedback/index.ts
@@ -3,12 +3,12 @@ import feedbackController from '../../controllers/feedback'
const router = express.Router()
// CREATE
-router.post('/:id', feedbackController.createChatMessageFeedbackForChatflow)
+router.post(['/', '/:id'], feedbackController.createChatMessageFeedbackForChatflow)
// READ
-router.get('/:id', feedbackController.getAllChatMessageFeedback)
+router.get(['/', '/:id'], feedbackController.getAllChatMessageFeedback)
// UPDATE
-router.put('/:id', feedbackController.updateChatMessageFeedbackForChatflow)
+router.put(['/', '/:id'], feedbackController.updateChatMessageFeedbackForChatflow)
export default router
diff --git a/packages/server/src/routes/flow-config/index.ts b/packages/server/src/routes/flow-config/index.ts
index 1aa46517e5b..bd841507a39 100644
--- a/packages/server/src/routes/flow-config/index.ts
+++ b/packages/server/src/routes/flow-config/index.ts
@@ -5,7 +5,7 @@ const router = express.Router()
// CREATE
// READ
-router.get('/:id', flowConfigsController.getSingleFlowConfig)
+router.get(['/', '/:id'], flowConfigsController.getSingleFlowConfig)
// UPDATE
diff --git a/packages/server/src/routes/internal-chat-messages/index.ts b/packages/server/src/routes/internal-chat-messages/index.ts
index fe05fdbc9c5..5dcf1e67505 100644
--- a/packages/server/src/routes/internal-chat-messages/index.ts
+++ b/packages/server/src/routes/internal-chat-messages/index.ts
@@ -5,7 +5,7 @@ const router = express.Router()
// CREATE
// READ
-router.get('/:id', chatMessagesController.getAllInternalChatMessages)
+router.get(['/', '/:id'], chatMessagesController.getAllInternalChatMessages)
// UPDATE
diff --git a/packages/server/src/routes/internal-predictions/index.ts b/packages/server/src/routes/internal-predictions/index.ts
index 6e1c17ba3e6..8e39dce20bc 100644
--- a/packages/server/src/routes/internal-predictions/index.ts
+++ b/packages/server/src/routes/internal-predictions/index.ts
@@ -3,6 +3,6 @@ import internalPredictionsController from '../../controllers/internal-prediction
const router = express.Router()
// CREATE
-router.post('/:id', internalPredictionsController.createInternalPrediction)
+router.post(['/', '/:id'], internalPredictionsController.createInternalPrediction)
export default router
diff --git a/packages/server/src/routes/node-icons/index.ts b/packages/server/src/routes/node-icons/index.ts
index 0781226addc..3dc51b96cbf 100644
--- a/packages/server/src/routes/node-icons/index.ts
+++ b/packages/server/src/routes/node-icons/index.ts
@@ -5,7 +5,7 @@ const router = express.Router()
// CREATE
// READ
-router.get('/:name', nodesController.getSingleNodeIcon)
+router.get(['/', '/:name'], nodesController.getSingleNodeIcon)
// UPDATE
diff --git a/packages/server/src/routes/node-load-methods/index.ts b/packages/server/src/routes/node-load-methods/index.ts
index 941190f1fd6..317fd81cfa1 100644
--- a/packages/server/src/routes/node-load-methods/index.ts
+++ b/packages/server/src/routes/node-load-methods/index.ts
@@ -2,6 +2,6 @@ import express from 'express'
import nodesRouter from '../../controllers/nodes'
const router = express.Router()
-router.post('/:name', nodesRouter.getSingleNodeAsyncOptions)
+router.post(['/', '/:name'], nodesRouter.getSingleNodeAsyncOptions)
export default router
diff --git a/packages/server/src/routes/nodes/index.ts b/packages/server/src/routes/nodes/index.ts
index b875036ef15..fd0369308ff 100644
--- a/packages/server/src/routes/nodes/index.ts
+++ b/packages/server/src/routes/nodes/index.ts
@@ -4,6 +4,6 @@ const router = express.Router()
// READ
router.get('/', nodesController.getAllNodes)
-router.get('/:name', nodesController.getNodeByName)
+router.get(['/', '/:name'], nodesController.getNodeByName)
export default router
diff --git a/packages/server/src/routes/openai-assistants/index.ts b/packages/server/src/routes/openai-assistants/index.ts
index 6e3378fd923..1c82a921480 100644
--- a/packages/server/src/routes/openai-assistants/index.ts
+++ b/packages/server/src/routes/openai-assistants/index.ts
@@ -6,7 +6,7 @@ const router = express.Router()
// READ
router.get('/', openaiAssistantsController.getAllOpenaiAssistants)
-router.get('/:id', openaiAssistantsController.getSingleOpenaiAssistant)
+router.get(['/', '/:id'], openaiAssistantsController.getSingleOpenaiAssistant)
// UPDATE
diff --git a/packages/server/src/routes/predictions/index.ts b/packages/server/src/routes/predictions/index.ts
index 613c6760106..ded2d34248d 100644
--- a/packages/server/src/routes/predictions/index.ts
+++ b/packages/server/src/routes/predictions/index.ts
@@ -8,6 +8,6 @@ const router = express.Router()
const upload = multer({ dest: `${path.join(__dirname, '..', '..', '..', 'uploads')}/` })
// CREATE
-router.post('/:id', upload.array('files'), predictionsController.getRateLimiterMiddleware, predictionsController.createPrediction)
+router.post(['/', '/:id'], upload.array('files'), predictionsController.getRateLimiterMiddleware, predictionsController.createPrediction)
export default router
diff --git a/packages/server/src/routes/public-chatbots/index.ts b/packages/server/src/routes/public-chatbots/index.ts
index 5a367c68386..18ee9e4c4fd 100644
--- a/packages/server/src/routes/public-chatbots/index.ts
+++ b/packages/server/src/routes/public-chatbots/index.ts
@@ -5,7 +5,7 @@ const router = express.Router()
// CREATE
// READ
-router.get('/:id', chatflowsController.getSinglePublicChatbotConfig)
+router.get(['/', '/:id'], chatflowsController.getSinglePublicChatbotConfig)
// UPDATE
diff --git a/packages/server/src/routes/public-chatflows/index.ts b/packages/server/src/routes/public-chatflows/index.ts
index 97e23ea7987..640fe3a6da1 100644
--- a/packages/server/src/routes/public-chatflows/index.ts
+++ b/packages/server/src/routes/public-chatflows/index.ts
@@ -5,7 +5,7 @@ const router = express.Router()
// CREATE
// READ
-router.get('/:id', chatflowsController.getSinglePublicChatflow)
+router.get(['/', '/:id'], chatflowsController.getSinglePublicChatflow)
// UPDATE
diff --git a/packages/server/src/routes/stats/index.ts b/packages/server/src/routes/stats/index.ts
index ea6d8db3c21..8ca64d3dab7 100644
--- a/packages/server/src/routes/stats/index.ts
+++ b/packages/server/src/routes/stats/index.ts
@@ -4,6 +4,6 @@ import statsController from '../../controllers/stats'
const router = express.Router()
// READ
-router.get('/:id', statsController.getChatflowStats)
+router.get(['/', '/:id'], statsController.getChatflowStats)
export default router
diff --git a/packages/server/src/routes/tools/index.ts b/packages/server/src/routes/tools/index.ts
index 4d63b16152d..40acfed25b9 100644
--- a/packages/server/src/routes/tools/index.ts
+++ b/packages/server/src/routes/tools/index.ts
@@ -8,12 +8,12 @@ router.post('/', toolsController.creatTool)
// READ
router.get('/', toolsController.getAllTools)
-router.get('/:id', toolsController.getToolById)
+router.get(['/', '/:id'], toolsController.getToolById)
// UPDATE
-router.put('/:id', toolsController.updateTool)
+router.put(['/', '/:id'], toolsController.updateTool)
// DELETE
-router.delete('/:id', toolsController.deleteTool)
+router.delete(['/', '/:id'], toolsController.deleteTool)
export default router
diff --git a/packages/server/src/routes/upsert-history/index.ts b/packages/server/src/routes/upsert-history/index.ts
index 1f4d9d02a5d..3e3c9c1a853 100644
--- a/packages/server/src/routes/upsert-history/index.ts
+++ b/packages/server/src/routes/upsert-history/index.ts
@@ -5,7 +5,7 @@ const router = express.Router()
// CREATE
// READ
-router.get('/:id', upsertHistoryController.getAllUpsertHistory)
+router.get(['/', '/:id'], upsertHistoryController.getAllUpsertHistory)
// PATCH
router.patch('/', upsertHistoryController.patchDeleteUpsertHistory)
diff --git a/packages/server/src/routes/variables/index.ts b/packages/server/src/routes/variables/index.ts
index eece5558878..f6d3625a454 100644
--- a/packages/server/src/routes/variables/index.ts
+++ b/packages/server/src/routes/variables/index.ts
@@ -10,9 +10,9 @@ router.post('/', variablesController.createVariable)
router.get('/', variablesController.getAllVariables)
// UPDATE
-router.put('/:id', variablesController.updateVariable)
+router.put(['/', '/:id'], variablesController.updateVariable)
// DELETE
-router.delete('/:id', variablesController.deleteVariable)
+router.delete(['/', '/:id'], variablesController.deleteVariable)
export default router
diff --git a/packages/server/src/routes/vectors/index.ts b/packages/server/src/routes/vectors/index.ts
index 21ffd97d44d..b0da82b64ba 100644
--- a/packages/server/src/routes/vectors/index.ts
+++ b/packages/server/src/routes/vectors/index.ts
@@ -8,7 +8,12 @@ const router = express.Router()
const upload = multer({ dest: `${path.join(__dirname, '..', '..', '..', 'uploads')}/` })
// CREATE
-router.post('/upsert/:id', upload.array('files'), vectorsController.getRateLimiterMiddleware, vectorsController.upsertVectorMiddleware)
-router.post('/internal-upsert/:id', vectorsController.createInternalUpsert)
+router.post(
+ ['/upsert/', '/upsert/:id'],
+ upload.array('files'),
+ vectorsController.getRateLimiterMiddleware,
+ vectorsController.upsertVectorMiddleware
+)
+router.post(['/internal-upsert/', '/internal-upsert/:id'], vectorsController.createInternalUpsert)
export default router
diff --git a/packages/server/src/routes/verify/index.ts b/packages/server/src/routes/verify/index.ts
index 414e6d0f3ec..b00a59aa3aa 100644
--- a/packages/server/src/routes/verify/index.ts
+++ b/packages/server/src/routes/verify/index.ts
@@ -3,6 +3,6 @@ import apikeyController from '../../controllers/apikey'
const router = express.Router()
// READ
-router.get('/apikey/:apikey', apikeyController.verifyApiKey)
+router.get(['/apikey/', '/apikey/:apikey'], apikeyController.verifyApiKey)
export default router
From 15fabee3773809b5dd23b1943ae73d19e02c20c5 Mon Sep 17 00:00:00 2001
From: ocflowiseai <154992625+ocflowiseai@users.noreply.github.com>
Date: Mon, 8 Apr 2024 11:40:54 +0200
Subject: [PATCH 16/18] Reconfigure the route precondition checks
---
packages/server/src/controllers/apikey/index.ts | 8 ++++----
.../server/src/controllers/assistants/index.ts | 10 +++++-----
.../src/controllers/chat-messages/index.ts | 6 +++---
.../server/src/controllers/chatflows/index.ts | 16 ++++++++--------
.../server/src/controllers/credentials/index.ts | 10 +++++-----
.../server/src/controllers/feedback/index.ts | 8 ++++----
.../server/src/controllers/flow-configs/index.ts | 2 +-
.../server/src/controllers/node-configs/index.ts | 2 +-
packages/server/src/controllers/nodes/index.ts | 4 ++--
.../src/controllers/openai-assistants/index.ts | 2 +-
.../server/src/controllers/predictions/index.ts | 4 ++--
packages/server/src/controllers/stats/index.ts | 2 +-
packages/server/src/controllers/tools/index.ts | 10 +++++-----
.../server/src/controllers/variables/index.ts | 4 ++--
14 files changed, 44 insertions(+), 44 deletions(-)
diff --git a/packages/server/src/controllers/apikey/index.ts b/packages/server/src/controllers/apikey/index.ts
index 26483b54293..a2a86406004 100644
--- a/packages/server/src/controllers/apikey/index.ts
+++ b/packages/server/src/controllers/apikey/index.ts
@@ -28,10 +28,10 @@ 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 === '') {
+ 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 === '') {
+ 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)
@@ -44,7 +44,7 @@ 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 === '') {
+ 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)
@@ -57,7 +57,7 @@ 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 === '') {
+ 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)
diff --git a/packages/server/src/controllers/assistants/index.ts b/packages/server/src/controllers/assistants/index.ts
index fbfa106ab34..7b852fb7d81 100644
--- a/packages/server/src/controllers/assistants/index.ts
+++ b/packages/server/src/controllers/assistants/index.ts
@@ -5,7 +5,7 @@ import { StatusCodes } from 'http-status-codes'
const creatAssistant = async (req: Request, res: Response, next: NextFunction) => {
try {
- if (typeof req.body === 'undefined' || req.body === '') {
+ if (!req.body) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: assistantsController.creatAssistant - body not provided!`
@@ -20,7 +20,7 @@ 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 === '') {
+ if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: assistantsController.deleteAssistant - id not provided!`
@@ -46,7 +46,7 @@ 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 === '') {
+ if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: assistantsController.getAssistantById - id not provided!`
@@ -62,13 +62,13 @@ 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 === '') {
+ 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 === '') {
+ if (!req.body) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: assistantsController.updateAssistant - body not provided!`
diff --git a/packages/server/src/controllers/chat-messages/index.ts b/packages/server/src/controllers/chat-messages/index.ts
index d418f4bf834..7c32fb4caff 100644
--- a/packages/server/src/controllers/chat-messages/index.ts
+++ b/packages/server/src/controllers/chat-messages/index.ts
@@ -11,7 +11,7 @@ import { StatusCodes } from 'http-status-codes'
const createChatMessage = async (req: Request, res: Response, next: NextFunction) => {
try {
- if (typeof req.body === 'undefined' || req.body === '') {
+ if (!req.body) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
'Error: chatMessagesController.createChatMessage - request body not provided!'
@@ -49,7 +49,7 @@ 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 === '') {
+ if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: chatMessageController.getAllChatMessages - id not provided!`
@@ -105,7 +105,7 @@ 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 === '') {
+ if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
'Error: chatMessagesController.removeAllChatMessages - id not provided!'
diff --git a/packages/server/src/controllers/chatflows/index.ts b/packages/server/src/controllers/chatflows/index.ts
index ddfdb3e5add..fdac0896515 100644
--- a/packages/server/src/controllers/chatflows/index.ts
+++ b/packages/server/src/controllers/chatflows/index.ts
@@ -8,7 +8,7 @@ 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 === '') {
+ if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: chatflowsRouter.checkIfChatflowIsValidForStreaming - id not provided!`
@@ -23,7 +23,7 @@ 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 === '') {
+ if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: chatflowsRouter.checkIfChatflowIsValidForUploads - id not provided!`
@@ -38,7 +38,7 @@ 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 === '') {
+ 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)
@@ -76,7 +76,7 @@ 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 === '') {
+ 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)
@@ -88,7 +88,7 @@ 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 === '') {
+ if (!req.body) {
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: chatflowsRouter.saveChatflow - body not provided!`)
}
const body = req.body
@@ -103,7 +103,7 @@ 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 === '') {
+ 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)
@@ -127,7 +127,7 @@ 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 === '') {
+ if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: chatflowsRouter.updateChatflow - id not provided!`)
}
const apiResponse = await chatflowsService.getSinglePublicChatflow(req.params.id)
@@ -139,7 +139,7 @@ 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 === '') {
+ if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: chatflowsRouter.getSinglePublicChatbotConfig - id not provided!`
diff --git a/packages/server/src/controllers/credentials/index.ts b/packages/server/src/controllers/credentials/index.ts
index 2be8945cc8c..ad937443045 100644
--- a/packages/server/src/controllers/credentials/index.ts
+++ b/packages/server/src/controllers/credentials/index.ts
@@ -5,7 +5,7 @@ import { StatusCodes } from 'http-status-codes'
const createCredential = async (req: Request, res: Response, next: NextFunction) => {
try {
- if (typeof req.body === 'undefined' || req.body === '') {
+ if (!req.body) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: credentialsController.createCredential - body not provided!`
@@ -20,7 +20,7 @@ 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 === '') {
+ if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: credentialsController.deleteCredentials - id not provided!`
@@ -44,7 +44,7 @@ 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 === '') {
+ if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: credentialsController.getCredentialById - id not provided!`
@@ -59,13 +59,13 @@ 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 === '') {
+ 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 === '') {
+ if (!req.body) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: credentialsController.updateCredential - body not provided!`
diff --git a/packages/server/src/controllers/feedback/index.ts b/packages/server/src/controllers/feedback/index.ts
index 0501a62a3c0..936a3b87912 100644
--- a/packages/server/src/controllers/feedback/index.ts
+++ b/packages/server/src/controllers/feedback/index.ts
@@ -5,7 +5,7 @@ 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 === '') {
+ if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: feedbackController.getAllChatMessageFeedback - id not provided!`
@@ -25,7 +25,7 @@ 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 === '') {
+ if (!req.body) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: feedbackController.createChatMessageFeedbackForChatflow - body not provided!`
@@ -40,13 +40,13 @@ const createChatMessageFeedbackForChatflow = async (req: Request, res: Response,
const updateChatMessageFeedbackForChatflow = async (req: Request, res: Response, next: NextFunction) => {
try {
- if (typeof req.body === 'undefined' || req.body === '') {
+ if (!req.body) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: feedbackController.updateChatMessageFeedbackForChatflow - body not provided!`
)
}
- if (typeof req.params.id === 'undefined' || req.params.id === '') {
+ if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: feedbackController.updateChatMessageFeedbackForChatflow - id not provided!`
diff --git a/packages/server/src/controllers/flow-configs/index.ts b/packages/server/src/controllers/flow-configs/index.ts
index b8acd9012e4..c0926266085 100644
--- a/packages/server/src/controllers/flow-configs/index.ts
+++ b/packages/server/src/controllers/flow-configs/index.ts
@@ -5,7 +5,7 @@ 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 === '') {
+ if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: flowConfigsController.getSingleFlowConfig - id not provided!`
diff --git a/packages/server/src/controllers/node-configs/index.ts b/packages/server/src/controllers/node-configs/index.ts
index fe2903a1734..d6ef4a467b7 100644
--- a/packages/server/src/controllers/node-configs/index.ts
+++ b/packages/server/src/controllers/node-configs/index.ts
@@ -5,7 +5,7 @@ import { StatusCodes } from 'http-status-codes'
const getAllNodeConfigs = async (req: Request, res: Response, next: NextFunction) => {
try {
- if (typeof req.body === 'undefined' || req.body === '') {
+ if (!req.body) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: nodeConfigsController.getAllNodeConfigs - body not provided!`
diff --git a/packages/server/src/controllers/nodes/index.ts b/packages/server/src/controllers/nodes/index.ts
index 0d815f332c9..fb6426fa498 100644
--- a/packages/server/src/controllers/nodes/index.ts
+++ b/packages/server/src/controllers/nodes/index.ts
@@ -38,7 +38,7 @@ 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 === '') {
+ if (!req.body) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: nodesController.getSingleNodeAsyncOptions - body not provided!`
@@ -59,7 +59,7 @@ 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 === '') {
+ if (!req.body) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: nodesController.executeCustomFunction - body not provided!`
diff --git a/packages/server/src/controllers/openai-assistants/index.ts b/packages/server/src/controllers/openai-assistants/index.ts
index dc36db52ee9..ca434add338 100644
--- a/packages/server/src/controllers/openai-assistants/index.ts
+++ b/packages/server/src/controllers/openai-assistants/index.ts
@@ -26,7 +26,7 @@ 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 === '') {
+ if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: openaiAssistantsController.getSingleOpenaiAssistant - id not provided!`
diff --git a/packages/server/src/controllers/predictions/index.ts b/packages/server/src/controllers/predictions/index.ts
index 3816f40e67a..aaebb92d400 100644
--- a/packages/server/src/controllers/predictions/index.ts
+++ b/packages/server/src/controllers/predictions/index.ts
@@ -9,13 +9,13 @@ 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 === '') {
+ 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 === '') {
+ if (!req.body) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: predictionsController.createPrediction - body not provided!`
diff --git a/packages/server/src/controllers/stats/index.ts b/packages/server/src/controllers/stats/index.ts
index a8ff0a272fd..b9a2d450fbd 100644
--- a/packages/server/src/controllers/stats/index.ts
+++ b/packages/server/src/controllers/stats/index.ts
@@ -6,7 +6,7 @@ import { StatusCodes } from 'http-status-codes'
const getChatflowStats = async (req: Request, res: Response, next: NextFunction) => {
try {
- if (typeof req.params.id === 'undefined' || req.params.id === '') {
+ 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
diff --git a/packages/server/src/controllers/tools/index.ts b/packages/server/src/controllers/tools/index.ts
index b45eeba20a2..acc19005d10 100644
--- a/packages/server/src/controllers/tools/index.ts
+++ b/packages/server/src/controllers/tools/index.ts
@@ -5,7 +5,7 @@ import { StatusCodes } from 'http-status-codes'
const creatTool = async (req: Request, res: Response, next: NextFunction) => {
try {
- if (typeof req.body === 'undefined' || req.body === '') {
+ if (!req.body) {
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: toolsController.creatTool - body not provided!`)
}
const apiResponse = await toolsService.creatTool(req.body)
@@ -17,7 +17,7 @@ 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 === '') {
+ 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)
@@ -38,7 +38,7 @@ 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 === '') {
+ 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)
@@ -50,10 +50,10 @@ 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 === '') {
+ 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 === '') {
+ 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)
diff --git a/packages/server/src/controllers/variables/index.ts b/packages/server/src/controllers/variables/index.ts
index 67eaa8f27e4..a124255a1ec 100644
--- a/packages/server/src/controllers/variables/index.ts
+++ b/packages/server/src/controllers/variables/index.ts
@@ -24,7 +24,7 @@ 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 === '') {
+ 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)
@@ -45,7 +45,7 @@ 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 === '') {
+ 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') {
From c8b1239c908a4d2491d8ed3a2bee4665be7fcce4 Mon Sep 17 00:00:00 2001
From: ocflowiseai <154992625+ocflowiseai@users.noreply.github.com>
Date: Mon, 8 Apr 2024 11:48:50 +0200
Subject: [PATCH 17/18] Fix router precondition checks
---
packages/server/src/controllers/apikey/index.ts | 2 +-
packages/server/src/controllers/chatflows/index.ts | 2 +-
.../server/src/controllers/components-credentials/index.ts | 4 ++--
packages/server/src/controllers/fetch-links/index.ts | 6 +++---
packages/server/src/controllers/load-prompts/index.ts | 2 +-
packages/server/src/controllers/nodes/index.ts | 6 +++---
packages/server/src/controllers/openai-assistants/index.ts | 4 ++--
7 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/packages/server/src/controllers/apikey/index.ts b/packages/server/src/controllers/apikey/index.ts
index a2a86406004..1a2ad3af5e6 100644
--- a/packages/server/src/controllers/apikey/index.ts
+++ b/packages/server/src/controllers/apikey/index.ts
@@ -15,7 +15,7 @@ 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 === '') {
+ 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)
diff --git a/packages/server/src/controllers/chatflows/index.ts b/packages/server/src/controllers/chatflows/index.ts
index fdac0896515..79ef2265d30 100644
--- a/packages/server/src/controllers/chatflows/index.ts
+++ b/packages/server/src/controllers/chatflows/index.ts
@@ -60,7 +60,7 @@ 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 === '') {
+ if (typeof req.params === 'undefined' || !req.params.apiKey) {
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: chatflowsRouter.getChatflowById - apiKey not provided!`)
}
const apiKey = await getApiKey(req.params.apiKey)
diff --git a/packages/server/src/controllers/components-credentials/index.ts b/packages/server/src/controllers/components-credentials/index.ts
index 32784d836f0..de99a9140d0 100644
--- a/packages/server/src/controllers/components-credentials/index.ts
+++ b/packages/server/src/controllers/components-credentials/index.ts
@@ -16,7 +16,7 @@ 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 === '') {
+ if (typeof req.params === 'undefined' || !req.params.name) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: componentsCredentialsController.getComponentByName - name not provided!`
@@ -32,7 +32,7 @@ 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 === '') {
+ if (typeof req.params === 'undefined' || !req.params.name) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: componentsCredentialsController.getSingleComponentsCredentialIcon - name not provided!`
diff --git a/packages/server/src/controllers/fetch-links/index.ts b/packages/server/src/controllers/fetch-links/index.ts
index 10f5a486be9..f3acce52e7e 100644
--- a/packages/server/src/controllers/fetch-links/index.ts
+++ b/packages/server/src/controllers/fetch-links/index.ts
@@ -5,16 +5,16 @@ 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 === '') {
+ 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 === '') {
+ 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 === '') {
+ 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(
diff --git a/packages/server/src/controllers/load-prompts/index.ts b/packages/server/src/controllers/load-prompts/index.ts
index 4e4a3acbcfc..6437e491b0e 100644
--- a/packages/server/src/controllers/load-prompts/index.ts
+++ b/packages/server/src/controllers/load-prompts/index.ts
@@ -5,7 +5,7 @@ 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 === '') {
+ if (typeof req.body === 'undefined' || !req.body.promptName) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: loadPromptsController.createPrompt - promptName not provided!`
diff --git a/packages/server/src/controllers/nodes/index.ts b/packages/server/src/controllers/nodes/index.ts
index fb6426fa498..eb20e4008eb 100644
--- a/packages/server/src/controllers/nodes/index.ts
+++ b/packages/server/src/controllers/nodes/index.ts
@@ -14,7 +14,7 @@ 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 === '') {
+ 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)
@@ -26,7 +26,7 @@ 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 === '') {
+ 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)
@@ -44,7 +44,7 @@ const getSingleNodeAsyncOptions = async (req: Request, res: Response, next: Next
`Error: nodesController.getSingleNodeAsyncOptions - body not provided!`
)
}
- if (typeof req.params.name === 'undefined' || req.params.name === '') {
+ if (typeof req.params === 'undefined' || !req.params.name) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: nodesController.getSingleNodeAsyncOptions - name not provided!`
diff --git a/packages/server/src/controllers/openai-assistants/index.ts b/packages/server/src/controllers/openai-assistants/index.ts
index ca434add338..4e944038509 100644
--- a/packages/server/src/controllers/openai-assistants/index.ts
+++ b/packages/server/src/controllers/openai-assistants/index.ts
@@ -10,7 +10,7 @@ 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 === '') {
+ if (typeof req.query === 'undefined' || !req.query.credential) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: openaiAssistantsController.getAllOpenaiAssistants - credential not provided!`
@@ -32,7 +32,7 @@ const getSingleOpenaiAssistant = async (req: Request, res: Response, next: NextF
`Error: openaiAssistantsController.getSingleOpenaiAssistant - id not provided!`
)
}
- if (typeof req.query.credential === 'undefined' || req.query.credential === '') {
+ if (typeof req.query === 'undefined' || !req.query.credential) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: openaiAssistantsController.getSingleOpenaiAssistant - credential not provided!`
From 53233a209d206b4961738358310b3bda35b52c77 Mon Sep 17 00:00:00 2001
From: Henry
Date: Thu, 11 Apr 2024 02:25:36 +0100
Subject: [PATCH 18/18] cleanup status codes, get proper error messages
---
.../src/controllers/assistants/index.ts | 12 ++---
.../server/src/controllers/chatflows/index.ts | 10 ++++-
.../src/controllers/node-icons/index.ts | 4 +-
.../server/src/controllers/stats/index.ts | 8 +++-
.../server/src/controllers/tools/index.ts | 8 ++--
.../server/src/controllers/vectors/index.ts | 7 ++-
packages/server/src/errors/utils.ts | 25 +++++++++++
.../server/src/routes/assistants/index.ts | 2 +-
packages/server/src/routes/tools/index.ts | 2 +-
packages/server/src/services/apikey/index.ts | 13 +++---
.../server/src/services/assistants/index.ts | 38 +++++++++++-----
.../src/services/chat-messages/index.ts | 20 ++++++---
.../server/src/services/chatflows/index.ts | 45 ++++++++++++++-----
.../services/components-credentials/index.ts | 17 +++----
.../server/src/services/credentials/index.ts | 28 +++++++++---
.../server/src/services/feedback/index.ts | 12 +++--
.../server/src/services/fetch-links/index.ts | 8 +++-
.../server/src/services/flow-configs/index.ts | 8 +++-
.../server/src/services/load-prompts/index.ts | 8 +++-
.../server/src/services/marketplaces/index.ts | 8 +++-
.../server/src/services/node-configs/index.ts | 8 +++-
packages/server/src/services/nodes/index.ts | 30 ++++++++-----
.../src/services/openai-assistants/index.ts | 7 +--
.../server/src/services/predictions/index.ts | 10 +++--
packages/server/src/services/stats/index.ts | 8 +++-
packages/server/src/services/tools/index.ts | 17 +++----
.../src/services/upsert-history/index.ts | 13 ++++--
.../server/src/services/variables/index.ts | 28 +++++++++---
packages/server/src/services/vectors/index.ts | 11 ++---
.../server/src/services/versions/index.ts | 7 +--
.../server/src/utils/addChatflowsCount.ts | 3 +-
packages/server/src/utils/getUploadsConfig.ts | 8 +++-
packages/server/src/utils/upsertVector.ts | 33 +++++++++-----
.../src/ui-component/button/FlowListMenu.jsx | 6 +--
.../dialog/ManageScrapedLinksDialog.jsx | 2 +-
.../dialog/ViewMessagesDialog.jsx | 2 +-
.../ui-component/extended/AllowedDomains.jsx | 4 +-
.../src/ui-component/extended/AnalyseFlow.jsx | 4 +-
.../ui-component/extended/ChatFeedback.jsx | 4 +-
.../src/ui-component/extended/RateLimit.jsx | 4 +-
.../ui-component/extended/SpeechToText.jsx | 4 +-
.../ui-component/extended/StarterPrompts.jsx | 4 +-
packages/ui/src/views/apikey/APIKeyDialog.jsx | 8 +++-
packages/ui/src/views/apikey/index.jsx | 4 +-
.../src/views/assistants/AssistantDialog.jsx | 16 +++++--
packages/ui/src/views/canvas/index.jsx | 2 +-
.../ui/src/views/chatflows/ShareChatbot.jsx | 8 +++-
.../ui/src/views/chatmessage/ChatPopUp.jsx | 2 +-
.../credentials/AddEditCredentialDialog.jsx | 8 +++-
packages/ui/src/views/credentials/index.jsx | 4 +-
packages/ui/src/views/tools/ToolDialog.jsx | 16 +++++--
.../views/variables/AddEditVariableDialog.jsx | 8 +++-
packages/ui/src/views/variables/index.jsx | 4 +-
.../views/vectorstore/UpsertHistoryDialog.jsx | 4 +-
.../views/vectorstore/VectorStoreDialog.jsx | 2 +-
55 files changed, 413 insertions(+), 173 deletions(-)
create mode 100644 packages/server/src/errors/utils.ts
diff --git a/packages/server/src/controllers/assistants/index.ts b/packages/server/src/controllers/assistants/index.ts
index 7b852fb7d81..c252dc56616 100644
--- a/packages/server/src/controllers/assistants/index.ts
+++ b/packages/server/src/controllers/assistants/index.ts
@@ -3,15 +3,15 @@ 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 (!req.body) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
- `Error: assistantsController.creatAssistant - body not provided!`
+ `Error: assistantsController.createAssistant - body not provided!`
)
}
- const apiResponse = await assistantsService.creatAssistant(req.body)
+ const apiResponse = await assistantsService.createAssistant(req.body)
return res.json(apiResponse)
} catch (error) {
next(error)
@@ -27,7 +27,6 @@ const deleteAssistant = async (req: Request, res: Response, next: NextFunction)
)
}
const apiResponse = await assistantsService.deleteAssistant(req.params.id, req.query.isDeleteBoth)
-
return res.json(apiResponse)
} catch (error) {
next(error)
@@ -37,7 +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()
-
return res.json(apiResponse)
} catch (error) {
next(error)
@@ -53,7 +51,6 @@ const getAssistantById = async (req: Request, res: Response, next: NextFunction)
)
}
const apiResponse = await assistantsService.getAssistantById(req.params.id)
-
return res.json(apiResponse)
} catch (error) {
next(error)
@@ -75,7 +72,6 @@ const updateAssistant = async (req: Request, res: Response, next: NextFunction)
)
}
const apiResponse = await assistantsService.updateAssistant(req.params.id, req.body)
-
return res.json(apiResponse)
} catch (error) {
next(error)
@@ -83,7 +79,7 @@ const updateAssistant = async (req: Request, res: Response, next: NextFunction)
}
export default {
- creatAssistant,
+ createAssistant,
deleteAssistant,
getAllAssistants,
getAssistantById,
diff --git a/packages/server/src/controllers/chatflows/index.ts b/packages/server/src/controllers/chatflows/index.ts
index 79ef2265d30..8923bf55bbf 100644
--- a/packages/server/src/controllers/chatflows/index.ts
+++ b/packages/server/src/controllers/chatflows/index.ts
@@ -61,7 +61,10 @@ const getAllChatflows = async (req: Request, res: Response, next: NextFunction)
const getChatflowByApiKey = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.params === 'undefined' || !req.params.apiKey) {
- throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: chatflowsRouter.getChatflowById - apiKey not provided!`)
+ throw new InternalFlowiseError(
+ StatusCodes.PRECONDITION_FAILED,
+ `Error: chatflowsRouter.getChatflowByApiKey - apiKey not provided!`
+ )
}
const apiKey = await getApiKey(req.params.apiKey)
if (!apiKey) {
@@ -128,7 +131,10 @@ const updateChatflow = async (req: Request, res: Response, next: NextFunction) =
const getSinglePublicChatflow = async (req: Request, res: Response, next: NextFunction) => {
try {
if (typeof req.params === 'undefined' || !req.params.id) {
- throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: chatflowsRouter.updateChatflow - id not provided!`)
+ throw new InternalFlowiseError(
+ StatusCodes.PRECONDITION_FAILED,
+ `Error: chatflowsRouter.getSinglePublicChatflow - id not provided!`
+ )
}
const apiResponse = await chatflowsService.getSinglePublicChatflow(req.params.id)
return res.json(apiResponse)
diff --git a/packages/server/src/controllers/node-icons/index.ts b/packages/server/src/controllers/node-icons/index.ts
index 9d296ee63ab..70cb58e46f5 100644
--- a/packages/server/src/controllers/node-icons/index.ts
+++ b/packages/server/src/controllers/node-icons/index.ts
@@ -11,7 +11,7 @@ const getSingleNodeIcon = async (req: Request, res: Response, next: NextFunction
const nodeInstance = appServer.nodesPool.componentNodes[req.params.name]
if (nodeInstance.icon === undefined) {
throw new InternalFlowiseError(
- StatusCodes.PRECONDITION_FAILED,
+ StatusCodes.NOT_FOUND,
`Error: nodeIconController.getSingleNodeIcon - Node ${req.params.name} icon not found`
)
}
@@ -27,7 +27,7 @@ const getSingleNodeIcon = async (req: Request, res: Response, next: NextFunction
}
} else {
throw new InternalFlowiseError(
- StatusCodes.PRECONDITION_FAILED,
+ StatusCodes.NOT_FOUND,
`Error: nodeIconController.getSingleNodeIcon - Node ${req.params.name} not found`
)
}
diff --git a/packages/server/src/controllers/stats/index.ts b/packages/server/src/controllers/stats/index.ts
index b9a2d450fbd..e4dd4dad270 100644
--- a/packages/server/src/controllers/stats/index.ts
+++ b/packages/server/src/controllers/stats/index.ts
@@ -1,8 +1,9 @@
+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 { StatusCodes } from 'http-status-codes'
+import { getErrorMessage } from '../../errors/utils'
const getChatflowStats = async (req: Request, res: Response, next: NextFunction) => {
try {
@@ -24,7 +25,10 @@ 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)
diff --git a/packages/server/src/controllers/tools/index.ts b/packages/server/src/controllers/tools/index.ts
index acc19005d10..35398d13d3f 100644
--- a/packages/server/src/controllers/tools/index.ts
+++ b/packages/server/src/controllers/tools/index.ts
@@ -3,12 +3,12 @@ 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 (!req.body) {
- throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: toolsController.creatTool - body not provided!`)
+ throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: toolsController.createTool - body not provided!`)
}
- const apiResponse = await toolsService.creatTool(req.body)
+ const apiResponse = await toolsService.createTool(req.body)
return res.json(apiResponse)
} catch (error) {
next(error)
@@ -64,7 +64,7 @@ const updateTool = async (req: Request, res: Response, next: NextFunction) => {
}
export default {
- creatTool,
+ createTool,
deleteTool,
getAllTools,
getToolById,
diff --git a/packages/server/src/controllers/vectors/index.ts b/packages/server/src/controllers/vectors/index.ts
index 21f8e3da9fb..5d10bb68b1a 100644
--- a/packages/server/src/controllers/vectors/index.ts
+++ b/packages/server/src/controllers/vectors/index.ts
@@ -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)
}
diff --git a/packages/server/src/errors/utils.ts b/packages/server/src/errors/utils.ts
new file mode 100644
index 00000000000..12ba0a67099
--- /dev/null
+++ b/packages/server/src/errors/utils.ts
@@ -0,0 +1,25 @@
+type ErrorWithMessage = {
+ message: string
+}
+
+const isErrorWithMessage = (error: unknown): error is ErrorWithMessage => {
+ return (
+ typeof error === 'object' && error !== null && 'message' in error && typeof (error as Record).message === 'string'
+ )
+}
+
+const toErrorWithMessage = (maybeError: unknown): ErrorWithMessage => {
+ if (isErrorWithMessage(maybeError)) return maybeError
+
+ try {
+ return new Error(JSON.stringify(maybeError))
+ } catch {
+ // fallback in case there's an error stringifying the maybeError
+ // like with circular references for example.
+ return new Error(String(maybeError))
+ }
+}
+
+export const getErrorMessage = (error: unknown) => {
+ return toErrorWithMessage(error).message
+}
diff --git a/packages/server/src/routes/assistants/index.ts b/packages/server/src/routes/assistants/index.ts
index 2ca1254b8ec..7b01cdd0111 100644
--- a/packages/server/src/routes/assistants/index.ts
+++ b/packages/server/src/routes/assistants/index.ts
@@ -4,7 +4,7 @@ import assistantsController from '../../controllers/assistants'
const router = express.Router()
// CREATE
-router.post('/', assistantsController.creatAssistant)
+router.post('/', assistantsController.createAssistant)
// READ
router.get('/', assistantsController.getAllAssistants)
diff --git a/packages/server/src/routes/tools/index.ts b/packages/server/src/routes/tools/index.ts
index 40acfed25b9..e97fb5cf46d 100644
--- a/packages/server/src/routes/tools/index.ts
+++ b/packages/server/src/routes/tools/index.ts
@@ -4,7 +4,7 @@ import toolsController from '../../controllers/tools'
const router = express.Router()
// CREATE
-router.post('/', toolsController.creatTool)
+router.post('/', toolsController.createTool)
// READ
router.get('/', toolsController.getAllTools)
diff --git a/packages/server/src/services/apikey/index.ts b/packages/server/src/services/apikey/index.ts
index 5fa2d89d39d..0bb09d02cd3 100644
--- a/packages/server/src/services/apikey/index.ts
+++ b/packages/server/src/services/apikey/index.ts
@@ -1,8 +1,9 @@
+import { StatusCodes } from 'http-status-codes'
import { addAPIKey, deleteAPIKey, getAPIKeys, updateAPIKey } from '../../utils/apiKey'
import { addChatflowsCount } from '../../utils/addChatflowsCount'
import { getApiKey } from '../../utils/apiKey'
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
-import { StatusCodes } from 'http-status-codes'
+import { getErrorMessage } from '../../errors/utils'
const getAllApiKeys = async () => {
try {
@@ -10,7 +11,7 @@ const getAllApiKeys = async () => {
const dbResponse = await addChatflowsCount(keys)
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: apikeyService.getAllApiKeys - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: apikeyService.getAllApiKeys - ${getErrorMessage(error)}`)
}
}
@@ -20,7 +21,7 @@ const createApiKey = async (keyName: string) => {
const dbResponse = await addChatflowsCount(keys)
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: apikeyService.createApiKey - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: apikeyService.createApiKey - ${getErrorMessage(error)}`)
}
}
@@ -31,7 +32,7 @@ const updateApiKey = async (id: string, keyName: string) => {
const dbResponse = await addChatflowsCount(keys)
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: apikeyService.updateApiKey - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: apikeyService.updateApiKey - ${getErrorMessage(error)}`)
}
}
@@ -41,7 +42,7 @@ const deleteApiKey = async (id: string) => {
const dbResponse = await addChatflowsCount(keys)
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: apikeyService.deleteApiKey - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: apikeyService.deleteApiKey - ${getErrorMessage(error)}`)
}
}
@@ -54,7 +55,7 @@ const verifyApiKey = async (paramApiKey: string): Promise => {
const dbResponse = 'OK'
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: apikeyService.verifyApiKey - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: apikeyService.verifyApiKey - ${getErrorMessage(error)}`)
}
}
diff --git a/packages/server/src/services/assistants/index.ts b/packages/server/src/services/assistants/index.ts
index 394ed96ee92..f451c473e38 100644
--- a/packages/server/src/services/assistants/index.ts
+++ b/packages/server/src/services/assistants/index.ts
@@ -1,15 +1,16 @@
import OpenAI from 'openai'
import path from 'path'
import * as fs from 'fs'
+import { StatusCodes } from 'http-status-codes'
import { uniqWith, isEqual } from 'lodash'
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
import { Assistant } from '../../database/entities/Assistant'
import { Credential } from '../../database/entities/Credential'
import { getUserHome, decryptCredentialData, getAppVersion } from '../../utils'
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
-import { StatusCodes } from 'http-status-codes'
+import { getErrorMessage } from '../../errors/utils'
-const creatAssistant = async (requestBody: any): Promise => {
+const createAssistant = async (requestBody: any): Promise => {
try {
const appServer = getRunningExpressApp()
if (!requestBody.details) {
@@ -111,7 +112,7 @@ const creatAssistant = async (requestBody: any): Promise => {
requestBody.details = JSON.stringify(newAssistantDetails)
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error creating new assistant: ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error creating new assistant - ${getErrorMessage(error)}`)
}
const newAssistant = new Assistant()
Object.assign(newAssistant, requestBody)
@@ -125,7 +126,10 @@ const creatAssistant = async (requestBody: any): Promise => {
})
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: assistantsService.creatTool - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: assistantsService.createAssistant - ${getErrorMessage(error)}`
+ )
}
}
@@ -163,11 +167,14 @@ const deleteAssistant = async (assistantId: string, isDeleteBoth: any): Promise<
if (error.status === 404 && error.type === 'invalid_request_error') {
return 'OK'
} else {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error deleting assistant: ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error deleting assistant - ${getErrorMessage(error)}`)
}
}
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: assistantsService.deleteTool - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: assistantsService.deleteAssistant - ${getErrorMessage(error)}`
+ )
}
}
@@ -177,7 +184,10 @@ const getAllAssistants = async (): Promise => {
const dbResponse = await appServer.AppDataSource.getRepository(Assistant).find()
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: assistantsService.getAllAssistants - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: assistantsService.getAllAssistants - ${getErrorMessage(error)}`
+ )
}
}
@@ -192,7 +202,10 @@ const getAssistantById = async (assistantId: string): Promise => {
}
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: assistantsService.getAssistantById - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: assistantsService.getAssistantById - ${getErrorMessage(error)}`
+ )
}
}
@@ -300,15 +313,18 @@ const updateAssistant = async (assistantId: string, requestBody: any): Promise) => {
@@ -18,7 +19,10 @@ const createChatMessage = async (chatMessage: Partial) => {
const dbResponse = await utilAddChatMessage(chatMessage)
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatMessagesService.createChatMessage - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: chatMessagesService.createChatMessage - ${getErrorMessage(error)}`
+ )
}
}
@@ -50,7 +54,10 @@ const getAllChatMessages = async (
)
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatMessagesService.getAllChatMessages - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: chatMessagesService.getAllChatMessages - ${getErrorMessage(error)}`
+ )
}
}
@@ -84,7 +91,7 @@ const getAllInternalChatMessages = async (
} catch (error) {
throw new InternalFlowiseError(
StatusCodes.INTERNAL_SERVER_ERROR,
- `Error: chatMessagesService.getAllInternalChatMessages - ${error}`
+ `Error: chatMessagesService.getAllInternalChatMessages - ${getErrorMessage(error)}`
)
}
}
@@ -109,7 +116,10 @@ const removeAllChatMessages = async (chatId: string, chatflowid: string, deleteO
const dbResponse = await appServer.AppDataSource.getRepository(ChatMessage).delete(deleteOptions)
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatMessagesService.removeAllChatMessages - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: chatMessagesService.removeAllChatMessages - ${getErrorMessage(error)}`
+ )
}
}
diff --git a/packages/server/src/services/chatflows/index.ts b/packages/server/src/services/chatflows/index.ts
index 00bb3176a70..58bbfbb14c1 100644
--- a/packages/server/src/services/chatflows/index.ts
+++ b/packages/server/src/services/chatflows/index.ts
@@ -20,6 +20,7 @@ import { ChatMessage } from '../../database/entities/ChatMessage'
import { ChatMessageFeedback } from '../../database/entities/ChatMessageFeedback'
import { UpsertHistory } from '../../database/entities/UpsertHistory'
import { containsBase64File, updateFlowDataWithFilePaths } from '../../utils/fileRepository'
+import { getErrorMessage } from '../../errors/utils'
// Check if chatflow valid for streaming
const checkIfChatflowIsValidForStreaming = async (chatflowId: string): Promise => {
@@ -78,7 +79,7 @@ const checkIfChatflowIsValidForStreaming = async (chatflowId: string): Promise => {
}
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.getAllChatflows - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: chatflowsService.deleteChatflow - ${getErrorMessage(error)}`
+ )
}
}
@@ -128,7 +132,10 @@ const getAllChatflows = async (): Promise => {
const dbResponse = await appServer.AppDataSource.getRepository(ChatFlow).find()
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.getAllChatflows - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: chatflowsService.getAllChatflows - ${getErrorMessage(error)}`
+ )
}
}
@@ -147,7 +154,10 @@ const getChatflowByApiKey = async (apiKeyId: string): Promise => {
}
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.getChatflowByApiKey - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: chatflowsService.getChatflowByApiKey - ${getErrorMessage(error)}`
+ )
}
}
@@ -162,7 +172,10 @@ const getChatflowById = async (chatflowId: string): Promise => {
}
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.getAllChatflows - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: chatflowsService.getChatflowById - ${getErrorMessage(error)}`
+ )
}
}
@@ -194,7 +207,10 @@ const saveChatflow = async (newChatFlow: ChatFlow): Promise => {
})
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.saveChatflow - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: chatflowsService.saveChatflow - ${getErrorMessage(error)}`
+ )
}
}
@@ -215,7 +231,10 @@ const updateChatflow = async (chatflow: ChatFlow, updateChatFlow: ChatFlow): Pro
}
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.updateChatflow - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: chatflowsService.updateChatflow - ${getErrorMessage(error)}`
+ )
}
}
@@ -233,7 +252,10 @@ const getSinglePublicChatflow = async (chatflowId: string): Promise => {
}
throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Chatflow ${chatflowId} not found`)
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.getSinglePublicChatflow - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: chatflowsService.getSinglePublicChatflow - ${getErrorMessage(error)}`
+ )
}
}
@@ -261,7 +283,10 @@ const getSinglePublicChatbotConfig = async (chatflowId: string): Promise =>
}
return 'OK'
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: chatflowsService.getSinglePublicChatbotConfig - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: chatflowsService.getSinglePublicChatbotConfig - ${getErrorMessage(error)}`
+ )
}
}
diff --git a/packages/server/src/services/components-credentials/index.ts b/packages/server/src/services/components-credentials/index.ts
index f851b1622a9..c65295b9024 100644
--- a/packages/server/src/services/components-credentials/index.ts
+++ b/packages/server/src/services/components-credentials/index.ts
@@ -1,7 +1,8 @@
import { cloneDeep } from 'lodash'
+import { StatusCodes } from 'http-status-codes'
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
-import { StatusCodes } from 'http-status-codes'
+import { getErrorMessage } from '../../errors/utils'
// Get all component credentials
const getAllComponentsCredentials = async (): Promise => {
@@ -16,7 +17,7 @@ const getAllComponentsCredentials = async (): Promise => {
} catch (error) {
throw new InternalFlowiseError(
StatusCodes.INTERNAL_SERVER_ERROR,
- `Error: componentsCredentialsService.getAllComponentsCredentials - ${error}`
+ `Error: componentsCredentialsService.getAllComponentsCredentials - ${getErrorMessage(error)}`
)
}
}
@@ -29,7 +30,7 @@ const getComponentByName = async (credentialName: string) => {
return appServer.nodesPool.componentCredentials[credentialName]
} else {
throw new InternalFlowiseError(
- StatusCodes.INTERNAL_SERVER_ERROR,
+ StatusCodes.NOT_FOUND,
`Error: componentsCredentialsService.getSingleComponentsCredential - Credential ${credentialName} not found`
)
}
@@ -40,7 +41,7 @@ const getComponentByName = async (credentialName: string) => {
dbResponse.push(appServer.nodesPool.componentCredentials[name])
} else {
throw new InternalFlowiseError(
- StatusCodes.INTERNAL_SERVER_ERROR,
+ StatusCodes.NOT_FOUND,
`Error: componentsCredentialsService.getSingleComponentsCredential - Credential ${name} not found`
)
}
@@ -50,7 +51,7 @@ const getComponentByName = async (credentialName: string) => {
} catch (error) {
throw new InternalFlowiseError(
StatusCodes.INTERNAL_SERVER_ERROR,
- `Error: componentsCredentialsService.getSingleComponentsCredential - ${error}`
+ `Error: componentsCredentialsService.getSingleComponentsCredential - ${getErrorMessage(error)}`
)
}
}
@@ -62,7 +63,7 @@ const getSingleComponentsCredentialIcon = async (credentialName: string) => {
if (Object.prototype.hasOwnProperty.call(appServer.nodesPool.componentCredentials, credentialName)) {
const credInstance = appServer.nodesPool.componentCredentials[credentialName]
if (credInstance.icon === undefined) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Credential ${credentialName} icon not found`)
+ throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Credential ${credentialName} icon not found`)
}
if (credInstance.icon.endsWith('.svg') || credInstance.icon.endsWith('.png') || credInstance.icon.endsWith('.jpg')) {
@@ -72,12 +73,12 @@ const getSingleComponentsCredentialIcon = async (credentialName: string) => {
throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Credential ${credentialName} icon is missing icon`)
}
} else {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Credential ${credentialName} not found`)
+ throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Credential ${credentialName} not found`)
}
} catch (error) {
throw new InternalFlowiseError(
StatusCodes.INTERNAL_SERVER_ERROR,
- `Error: componentsCredentialsService.getSingleComponentsCredentialIcon - ${error}`
+ `Error: componentsCredentialsService.getSingleComponentsCredentialIcon - ${getErrorMessage(error)}`
)
}
}
diff --git a/packages/server/src/services/credentials/index.ts b/packages/server/src/services/credentials/index.ts
index 8c012e14382..eed2eed05e9 100644
--- a/packages/server/src/services/credentials/index.ts
+++ b/packages/server/src/services/credentials/index.ts
@@ -1,10 +1,11 @@
import { omit } from 'lodash'
+import { StatusCodes } from 'http-status-codes'
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
import { Credential } from '../../database/entities/Credential'
import { transformToCredentialEntity, decryptCredentialData } from '../../utils'
import { ICredentialReturnResponse } from '../../Interface'
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
-import { StatusCodes } from 'http-status-codes'
+import { getErrorMessage } from '../../errors/utils'
const createCredential = async (requestBody: any) => {
try {
@@ -14,7 +15,10 @@ const createCredential = async (requestBody: any) => {
const dbResponse = await appServer.AppDataSource.getRepository(Credential).save(credential)
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: credentialsService.createCredential - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: credentialsService.createCredential - ${getErrorMessage(error)}`
+ )
}
}
@@ -28,7 +32,10 @@ const deleteCredentials = async (credentialId: string): Promise => {
}
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: credentialsService.deleteCredential - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: credentialsService.deleteCredential - ${getErrorMessage(error)}`
+ )
}
}
@@ -59,7 +66,10 @@ const getAllCredentials = async (paramCredentialName: any) => {
}
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: credentialsService.getAllCredentials - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: credentialsService.getAllCredentials - ${getErrorMessage(error)}`
+ )
}
}
@@ -85,7 +95,10 @@ const getCredentialById = async (credentialId: string): Promise => {
const dbResponse = omit(returnCredential, ['encryptedData'])
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: credentialsService.createCredential - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: credentialsService.createCredential - ${getErrorMessage(error)}`
+ )
}
}
@@ -103,7 +116,10 @@ const updateCredential = async (credentialId: string, requestBody: any): Promise
const dbResponse = await appServer.AppDataSource.getRepository(Credential).save(credential)
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: credentialsService.updateCredential - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: credentialsService.updateCredential - ${getErrorMessage(error)}`
+ )
}
}
diff --git a/packages/server/src/services/feedback/index.ts b/packages/server/src/services/feedback/index.ts
index e74788609ab..df6bc49ce83 100644
--- a/packages/server/src/services/feedback/index.ts
+++ b/packages/server/src/services/feedback/index.ts
@@ -1,9 +1,10 @@
+import { StatusCodes } from 'http-status-codes'
import { utilGetChatMessageFeedback } from '../../utils/getChatMessageFeedback'
import { utilAddChatMessageFeedback } from '../../utils/addChatMessageFeedback'
import { utilUpdateChatMessageFeedback } from '../../utils/updateChatMessageFeedback'
import { IChatMessageFeedback } from '../../Interface'
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
-import { StatusCodes } from 'http-status-codes'
+import { getErrorMessage } from '../../errors/utils'
// Get all chatmessage feedback from chatflowid
const getAllChatMessageFeedback = async (
@@ -17,7 +18,10 @@ const getAllChatMessageFeedback = async (
const dbResponse = await utilGetChatMessageFeedback(chatflowid, chatId, sortOrder, startDate, endDate)
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: feedbackService.getAllChatMessageFeedback - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: feedbackService.getAllChatMessageFeedback - ${getErrorMessage(error)}`
+ )
}
}
@@ -29,7 +33,7 @@ const createChatMessageFeedbackForChatflow = async (requestBody: Partial => {
try {
@@ -21,7 +22,10 @@ const getAllLinks = async (requestUrl: string, relativeLinksMethod: string, quer
}
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: fetchLinksService.getAllLinks - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: fetchLinksService.getAllLinks - ${getErrorMessage(error)}`
+ )
}
}
diff --git a/packages/server/src/services/flow-configs/index.ts b/packages/server/src/services/flow-configs/index.ts
index a09e7bc7b94..8ce05499f2c 100644
--- a/packages/server/src/services/flow-configs/index.ts
+++ b/packages/server/src/services/flow-configs/index.ts
@@ -1,9 +1,10 @@
+import { StatusCodes } from 'http-status-codes'
import { findAvailableConfigs } from '../../utils'
import { IReactFlowObject } from '../../Interface'
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
import chatflowsService from '../chatflows'
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
-import { StatusCodes } from 'http-status-codes'
+import { getErrorMessage } from '../../errors/utils'
const getSingleFlowConfig = async (chatflowId: string): Promise => {
try {
@@ -18,7 +19,10 @@ const getSingleFlowConfig = async (chatflowId: string): Promise => {
const dbResponse = findAvailableConfigs(nodes, appServer.nodesPool.componentCredentials)
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: flowConfigService.getSingleFlowConfig - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: flowConfigService.getSingleFlowConfig - ${getErrorMessage(error)}`
+ )
}
}
diff --git a/packages/server/src/services/load-prompts/index.ts b/packages/server/src/services/load-prompts/index.ts
index d4d8cba8633..5f041a838af 100644
--- a/packages/server/src/services/load-prompts/index.ts
+++ b/packages/server/src/services/load-prompts/index.ts
@@ -1,7 +1,8 @@
import { Client } from 'langchainhub'
+import { StatusCodes } from 'http-status-codes'
import { parsePrompt } from '../../utils/hub'
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
-import { StatusCodes } from 'http-status-codes'
+import { getErrorMessage } from '../../errors/utils'
const createPrompt = async (promptName: string): Promise => {
try {
@@ -15,7 +16,10 @@ const createPrompt = async (promptName: string): Promise => {
}
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: loadPromptsService.createPrompt - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: loadPromptsService.createPrompt - ${getErrorMessage(error)}`
+ )
}
}
diff --git a/packages/server/src/services/marketplaces/index.ts b/packages/server/src/services/marketplaces/index.ts
index b37f8ce93cd..54e43899cb5 100644
--- a/packages/server/src/services/marketplaces/index.ts
+++ b/packages/server/src/services/marketplaces/index.ts
@@ -1,7 +1,8 @@
import path from 'path'
import * as fs from 'fs'
-import { InternalFlowiseError } from '../../errors/internalFlowiseError'
import { StatusCodes } from 'http-status-codes'
+import { InternalFlowiseError } from '../../errors/internalFlowiseError'
+import { getErrorMessage } from '../../errors/utils'
// Get all templates for marketplaces
const getAllTemplates = async () => {
@@ -51,7 +52,10 @@ const getAllTemplates = async () => {
const dbResponse = sortedTemplates
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: marketplacesService.getAllTemplates - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: marketplacesService.getAllTemplates - ${getErrorMessage(error)}`
+ )
}
}
diff --git a/packages/server/src/services/node-configs/index.ts b/packages/server/src/services/node-configs/index.ts
index 8005f55f86f..0debdc5e770 100644
--- a/packages/server/src/services/node-configs/index.ts
+++ b/packages/server/src/services/node-configs/index.ts
@@ -1,8 +1,9 @@
+import { StatusCodes } from 'http-status-codes'
import { findAvailableConfigs } from '../../utils'
import { IReactFlowNode } from '../../Interface'
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
-import { StatusCodes } from 'http-status-codes'
+import { getErrorMessage } from '../../errors/utils'
const getAllNodeConfigs = async (requestBody: any) => {
try {
@@ -11,7 +12,10 @@ const getAllNodeConfigs = async (requestBody: any) => {
const dbResponse = findAvailableConfigs(nodes, appServer.nodesPool.componentCredentials)
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: nodeConfigsService.getAllNodeConfigs - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: nodeConfigsService.getAllNodeConfigs - ${getErrorMessage(error)}`
+ )
}
}
diff --git a/packages/server/src/services/nodes/index.ts b/packages/server/src/services/nodes/index.ts
index acf631e9952..715740e2f71 100644
--- a/packages/server/src/services/nodes/index.ts
+++ b/packages/server/src/services/nodes/index.ts
@@ -1,11 +1,12 @@
import { cloneDeep } from 'lodash'
+import { StatusCodes } from 'http-status-codes'
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
import { INodeData } from '../../Interface'
import { INodeOptionsValue, ICommonObject, handleEscapeCharacters } from 'flowise-components'
import { databaseEntities } from '../../utils'
import logger from '../../utils/logger'
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
-import { StatusCodes } from 'http-status-codes'
+import { getErrorMessage } from '../../errors/utils'
// Get all component nodes
const getAllNodes = async () => {
@@ -18,7 +19,7 @@ const getAllNodes = async () => {
}
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: nodesService.getAllNodes - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: nodesService.getAllNodes - ${getErrorMessage(error)}`)
}
}
@@ -30,10 +31,10 @@ const getNodeByName = async (nodeName: string) => {
const dbResponse = appServer.nodesPool.componentNodes[nodeName]
return dbResponse
} else {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Node ${nodeName} not found`)
+ throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Node ${nodeName} not found`)
}
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: nodesService.getAllNodes - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: nodesService.getAllNodes - ${getErrorMessage(error)}`)
}
}
@@ -44,7 +45,7 @@ const getSingleNodeIcon = async (nodeName: string) => {
if (Object.prototype.hasOwnProperty.call(appServer.nodesPool.componentNodes, nodeName)) {
const nodeInstance = appServer.nodesPool.componentNodes[nodeName]
if (nodeInstance.icon === undefined) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Node ${nodeName} icon not found`)
+ throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Node ${nodeName} icon not found`)
}
if (nodeInstance.icon.endsWith('.svg') || nodeInstance.icon.endsWith('.png') || nodeInstance.icon.endsWith('.jpg')) {
@@ -54,10 +55,13 @@ const getSingleNodeIcon = async (nodeName: string) => {
throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Node ${nodeName} icon is missing icon`)
}
} else {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Node ${nodeName} not found`)
+ throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Node ${nodeName} not found`)
}
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: nodesService.getSingleNodeIcon - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: nodesService.getSingleNodeIcon - ${getErrorMessage(error)}`
+ )
}
}
@@ -83,7 +87,10 @@ const getSingleNodeAsyncOptions = async (nodeName: string, requestBody: any): Pr
throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Node ${nodeName} not found`)
}
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: nodesService.getSingleNodeAsyncOptions - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: nodesService.getSingleNodeAsyncOptions - ${getErrorMessage(error)}`
+ )
}
}
@@ -116,10 +123,13 @@ const executeCustomFunction = async (requestBody: any) => {
throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error running custom function: ${error}`)
}
} else {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Node customFunction not found`)
+ throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Node customFunction not found`)
}
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: nodesService.executeCustomFunction - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: nodesService.executeCustomFunction - ${getErrorMessage(error)}`
+ )
}
}
diff --git a/packages/server/src/services/openai-assistants/index.ts b/packages/server/src/services/openai-assistants/index.ts
index c0afa2e057d..00ea5e60d5e 100644
--- a/packages/server/src/services/openai-assistants/index.ts
+++ b/packages/server/src/services/openai-assistants/index.ts
@@ -1,9 +1,10 @@
import OpenAI from 'openai'
+import { StatusCodes } from 'http-status-codes'
import { decryptCredentialData } from '../../utils'
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
import { Credential } from '../../database/entities/Credential'
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
-import { StatusCodes } from 'http-status-codes'
+import { getErrorMessage } from '../../errors/utils'
// ----------------------------------------
// Assistants
@@ -32,7 +33,7 @@ const getAllOpenaiAssistants = async (credentialId: string): Promise => {
} catch (error) {
throw new InternalFlowiseError(
StatusCodes.INTERNAL_SERVER_ERROR,
- `Error: openaiAssistantsService.getAllOpenaiAssistants - ${error}`
+ `Error: openaiAssistantsService.getAllOpenaiAssistants - ${getErrorMessage(error)}`
)
}
}
@@ -65,7 +66,7 @@ const getSingleOpenaiAssistant = async (credentialId: string, assistantId: strin
} catch (error) {
throw new InternalFlowiseError(
StatusCodes.INTERNAL_SERVER_ERROR,
- `Error: openaiAssistantsService.getSingleOpenaiAssistant - ${error}`
+ `Error: openaiAssistantsService.getSingleOpenaiAssistant - ${getErrorMessage(error)}`
)
}
}
diff --git a/packages/server/src/services/predictions/index.ts b/packages/server/src/services/predictions/index.ts
index 0c102bb4fe7..e7411fe6ac5 100644
--- a/packages/server/src/services/predictions/index.ts
+++ b/packages/server/src/services/predictions/index.ts
@@ -1,15 +1,19 @@
+import { Request } from 'express'
+import { Server } from 'socket.io'
import { StatusCodes } from 'http-status-codes'
import { utilBuildChatflow } from '../../utils/buildChatflow'
-import { Server } from 'socket.io'
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
-import { Request } from 'express'
+import { getErrorMessage } from '../../errors/utils'
const buildChatflow = async (fullRequest: Request, ioServer: Server) => {
try {
const dbResponse = await utilBuildChatflow(fullRequest, ioServer)
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, 'Error: predictionsServices.buildChatflow failed!')
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: predictionsServices.buildChatflow - ${getErrorMessage(error)}`
+ )
}
}
diff --git a/packages/server/src/services/stats/index.ts b/packages/server/src/services/stats/index.ts
index 5deae55ee83..2f6faff23fc 100644
--- a/packages/server/src/services/stats/index.ts
+++ b/packages/server/src/services/stats/index.ts
@@ -1,9 +1,10 @@
+import { StatusCodes } from 'http-status-codes'
import { chatType } from '../../Interface'
import { ChatMessage } from '../../database/entities/ChatMessage'
import { utilGetChatMessage } from '../../utils/getChatMessage'
import { ChatMessageFeedback } from '../../database/entities/ChatMessageFeedback'
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
-import { StatusCodes } from 'http-status-codes'
+import { getErrorMessage } from '../../errors/utils'
// get stats for showing in chatflow
const getChatflowStats = async (
@@ -38,7 +39,10 @@ const getChatflowStats = async (
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: statsService.getChatflowStats - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: statsService.getChatflowStats - ${getErrorMessage(error)}`
+ )
}
}
diff --git a/packages/server/src/services/tools/index.ts b/packages/server/src/services/tools/index.ts
index 98bde8e2329..f2e41400ca6 100644
--- a/packages/server/src/services/tools/index.ts
+++ b/packages/server/src/services/tools/index.ts
@@ -1,10 +1,11 @@
+import { StatusCodes } from 'http-status-codes'
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
import { Tool } from '../../database/entities/Tool'
import { getAppVersion } from '../../utils'
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
-import { StatusCodes } from 'http-status-codes'
+import { getErrorMessage } from '../../errors/utils'
-const creatTool = async (requestBody: any): Promise => {
+const createTool = async (requestBody: any): Promise => {
try {
const appServer = getRunningExpressApp()
const newTool = new Tool()
@@ -18,7 +19,7 @@ const creatTool = async (requestBody: any): Promise => {
})
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: toolsService.creatTool - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: toolsService.createTool - ${getErrorMessage(error)}`)
}
}
@@ -30,7 +31,7 @@ const deleteTool = async (toolId: string): Promise => {
})
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: toolsService.deleteTool - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: toolsService.deleteTool - ${getErrorMessage(error)}`)
}
}
@@ -40,7 +41,7 @@ const getAllTools = async (): Promise => {
const dbResponse = await appServer.AppDataSource.getRepository(Tool).find()
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: toolsService.getAllTools - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: toolsService.getAllTools - ${getErrorMessage(error)}`)
}
}
@@ -55,7 +56,7 @@ const getToolById = async (toolId: string): Promise => {
}
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: toolsService.getToolById - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: toolsService.getToolById - ${getErrorMessage(error)}`)
}
}
@@ -74,12 +75,12 @@ const updateTool = async (toolId: string, toolBody: any): Promise => {
const dbResponse = await appServer.AppDataSource.getRepository(Tool).save(tool)
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: toolsService.getToolById - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: toolsService.updateTool - ${getErrorMessage(error)}`)
}
}
export default {
- creatTool,
+ createTool,
deleteTool,
getAllTools,
getToolById,
diff --git a/packages/server/src/services/upsert-history/index.ts b/packages/server/src/services/upsert-history/index.ts
index a3920440a7e..72e484b1cb1 100644
--- a/packages/server/src/services/upsert-history/index.ts
+++ b/packages/server/src/services/upsert-history/index.ts
@@ -1,8 +1,9 @@
import { MoreThanOrEqual, LessThanOrEqual } from 'typeorm'
+import { StatusCodes } from 'http-status-codes'
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
import { UpsertHistory } from '../../database/entities/UpsertHistory'
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
-import { StatusCodes } from 'http-status-codes'
+import { getErrorMessage } from '../../errors/utils'
const getAllUpsertHistory = async (
sortOrder: string | undefined,
@@ -48,7 +49,10 @@ const getAllUpsertHistory = async (
return upsertHistory
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: upsertHistoryServices.getAllUpsertHistory - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: upsertHistoryServices.getAllUpsertHistory - ${getErrorMessage(error)}`
+ )
}
}
@@ -58,7 +62,10 @@ const patchDeleteUpsertHistory = async (ids: string[] = []): Promise => {
const dbResponse = await appServer.AppDataSource.getRepository(UpsertHistory).delete(ids)
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: upsertHistoryServices.patchUpsertHistory - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: upsertHistoryServices.patchDeleteUpsertHistory - ${getErrorMessage(error)}`
+ )
}
}
diff --git a/packages/server/src/services/variables/index.ts b/packages/server/src/services/variables/index.ts
index 60ea4c6120e..d2377dc217d 100644
--- a/packages/server/src/services/variables/index.ts
+++ b/packages/server/src/services/variables/index.ts
@@ -1,7 +1,8 @@
+import { StatusCodes } from 'http-status-codes'
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
import { Variable } from '../../database/entities/Variable'
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
-import { StatusCodes } from 'http-status-codes'
+import { getErrorMessage } from '../../errors/utils'
const createVariable = async (newVariable: Variable) => {
try {
@@ -10,7 +11,10 @@ const createVariable = async (newVariable: Variable) => {
const dbResponse = await appServer.AppDataSource.getRepository(Variable).save(variable)
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: variablesServices.createVariable - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: variablesServices.createVariable - ${getErrorMessage(error)}`
+ )
}
}
@@ -20,7 +24,10 @@ const deleteVariable = async (variableId: string): Promise => {
const dbResponse = await appServer.AppDataSource.getRepository(Variable).delete({ id: variableId })
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: variablesServices.deleteVariable - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: variablesServices.deleteVariable - ${getErrorMessage(error)}`
+ )
}
}
@@ -30,7 +37,10 @@ const getAllVariables = async () => {
const dbResponse = await appServer.AppDataSource.getRepository(Variable).find()
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: variablesServices.getAllVariables - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: variablesServices.getAllVariables - ${getErrorMessage(error)}`
+ )
}
}
@@ -42,7 +52,10 @@ const getVariableById = async (variableId: string) => {
})
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: variablesServices.getVariableById - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: variablesServices.getVariableById - ${getErrorMessage(error)}`
+ )
}
}
@@ -53,7 +66,10 @@ const updateVariable = async (variable: Variable, updatedVariable: Variable) =>
const dbResponse = await appServer.AppDataSource.getRepository(Variable).save(tmpUpdatedVariable)
return dbResponse
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: variablesServices.updateVariable - ${error}`)
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ `Error: variablesServices.updateVariable - ${getErrorMessage(error)}`
+ )
}
}
diff --git a/packages/server/src/services/vectors/index.ts b/packages/server/src/services/vectors/index.ts
index c16f9805fbe..15892f57d1e 100644
--- a/packages/server/src/services/vectors/index.ts
+++ b/packages/server/src/services/vectors/index.ts
@@ -1,13 +1,14 @@
-import { Request, Response } from 'express'
+import { Request } from 'express'
+import { StatusCodes } from 'http-status-codes'
import { upsertVector } from '../../utils/upsertVector'
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
-import { StatusCodes } from 'http-status-codes'
+import { getErrorMessage } from '../../errors/utils'
-const upsertVectorMiddleware = async (req: Request, res: Response, isInternal: boolean = false) => {
+const upsertVectorMiddleware = async (req: Request, isInternal: boolean = false) => {
try {
- await upsertVector(req, res, isInternal)
+ return await upsertVector(req, isInternal)
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: vectorsService.getRateLimiter - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: vectorsService.upsertVector - ${getErrorMessage(error)}`)
}
}
diff --git a/packages/server/src/services/versions/index.ts b/packages/server/src/services/versions/index.ts
index 00a97ee181e..f83006030f2 100644
--- a/packages/server/src/services/versions/index.ts
+++ b/packages/server/src/services/versions/index.ts
@@ -1,7 +1,8 @@
import path from 'path'
import * as fs from 'fs'
-import { InternalFlowiseError } from '../../errors/internalFlowiseError'
import { StatusCodes } from 'http-status-codes'
+import { InternalFlowiseError } from '../../errors/internalFlowiseError'
+import { getErrorMessage } from '../../errors/utils'
const getVersion = async () => {
try {
@@ -31,10 +32,10 @@ const getVersion = async () => {
version: parsedContent.version
}
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Version not found: ${error}`)
+ throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Version not found- ${getErrorMessage(error)}`)
}
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: versionService.getVersion - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: versionService.getVersion - ${getErrorMessage(error)}`)
}
}
diff --git a/packages/server/src/utils/addChatflowsCount.ts b/packages/server/src/utils/addChatflowsCount.ts
index 8c3464cf85c..ede05121cf4 100644
--- a/packages/server/src/utils/addChatflowsCount.ts
+++ b/packages/server/src/utils/addChatflowsCount.ts
@@ -2,6 +2,7 @@ import { StatusCodes } from 'http-status-codes'
import { ChatFlow } from '../database/entities/ChatFlow'
import { InternalFlowiseError } from '../errors/internalFlowiseError'
import { getRunningExpressApp } from '../utils/getRunningExpressApp'
+import { getErrorMessage } from '../errors/utils'
export const addChatflowsCount = async (keys: any) => {
try {
@@ -30,6 +31,6 @@ export const addChatflowsCount = async (keys: any) => {
}
return tmpResult
} catch (error) {
- throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: addChatflowsCount - ${error}`)
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Error: addChatflowsCount - ${getErrorMessage(error)}`)
}
}
diff --git a/packages/server/src/utils/getUploadsConfig.ts b/packages/server/src/utils/getUploadsConfig.ts
index 7be23a6cf56..bbc5eedd69e 100644
--- a/packages/server/src/utils/getUploadsConfig.ts
+++ b/packages/server/src/utils/getUploadsConfig.ts
@@ -1,7 +1,9 @@
+import { StatusCodes } from 'http-status-codes'
+import { INodeParams } from 'flowise-components'
import { ChatFlow } from '../database/entities/ChatFlow'
import { getRunningExpressApp } from '../utils/getRunningExpressApp'
import { IUploadFileSizeAndTypes, IReactFlowNode } from '../Interface'
-import { INodeParams } from 'flowise-components'
+import { InternalFlowiseError } from '../errors/internalFlowiseError'
/**
* Method that checks if uploads are enabled in the chatflow
@@ -12,7 +14,9 @@ export const utilGetUploadsConfig = async (chatflowid: string): Promise =>
const chatflow = await appServer.AppDataSource.getRepository(ChatFlow).findOneBy({
id: chatflowid
})
- if (!chatflow) return `Chatflow ${chatflowid} not found`
+ if (!chatflow) {
+ throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Chatflow ${chatflowid} not found`)
+ }
const uploadAllowedNodes = ['llmChain', 'conversationChain', 'mrklAgentChat', 'conversationalAgent']
const uploadProcessingNodes = ['chatOpenAI', 'chatAnthropic', 'awsChatBedrock', 'azureChatOpenAI']
diff --git a/packages/server/src/utils/upsertVector.ts b/packages/server/src/utils/upsertVector.ts
index d8714502ee4..0913786c0fc 100644
--- a/packages/server/src/utils/upsertVector.ts
+++ b/packages/server/src/utils/upsertVector.ts
@@ -1,4 +1,4 @@
-import { Request, Response } from 'express'
+import { Request } from 'express'
import * as fs from 'fs'
import { cloneDeep, omit } from 'lodash'
import { ICommonObject } from 'flowise-components'
@@ -20,14 +20,15 @@ import { IncomingInput, INodeDirectedGraph, IReactFlowObject, chatType } from '.
import { ChatFlow } from '../database/entities/ChatFlow'
import { getRunningExpressApp } from '../utils/getRunningExpressApp'
import { UpsertHistory } from '../database/entities/UpsertHistory'
+import { InternalFlowiseError } from '../errors/internalFlowiseError'
+import { StatusCodes } from 'http-status-codes'
/**
* Upsert documents
* @param {Request} req
- * @param {Response} res
* @param {boolean} isInternal
*/
-export const upsertVector = async (req: Request, res: Response, isInternal: boolean = false) => {
+export const upsertVector = async (req: Request, isInternal: boolean = false) => {
try {
const appServer = getRunningExpressApp()
const chatflowid = req.params.id
@@ -36,11 +37,15 @@ export const upsertVector = async (req: Request, res: Response, isInternal: bool
const chatflow = await appServer.AppDataSource.getRepository(ChatFlow).findOneBy({
id: chatflowid
})
- if (!chatflow) return res.status(404).send(`Chatflow ${chatflowid} not found`)
+ if (!chatflow) {
+ throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Chatflow ${chatflowid} not found`)
+ }
if (!isInternal) {
const isKeyValidated = await utilValidateKey(req, chatflow)
- if (!isKeyValidated) return res.status(401).send('Unauthorized')
+ if (!isKeyValidated) {
+ throw new InternalFlowiseError(StatusCodes.UNAUTHORIZED, `Unauthorized`)
+ }
}
const files = (req.files as any[]) || []
@@ -89,11 +94,14 @@ export const upsertVector = async (req: Request, res: Response, isInternal: bool
// Check if multiple vector store nodes exist, and if stopNodeId is specified
if (vsNodes.length > 1 && !stopNodeId) {
- return res.status(500).send('There are multiple vector nodes, please provide stopNodeId in body request')
+ throw new InternalFlowiseError(
+ StatusCodes.INTERNAL_SERVER_ERROR,
+ 'There are multiple vector nodes, please provide stopNodeId in body request'
+ )
} else if (vsNodes.length === 1 && !stopNodeId) {
stopNodeId = vsNodes[0].data.id
} else if (!vsNodes.length && !stopNodeId) {
- return res.status(500).send('No vector node found')
+ throw new InternalFlowiseError(StatusCodes.NOT_FOUND, 'No vector node found')
}
const { graph } = constructGraphs(nodes, edges, { isReversed: true })
@@ -154,9 +162,12 @@ export const upsertVector = async (req: Request, res: Response, isInternal: bool
stopNodeId
}
})
- return res.status(201).json(upsertedResult['result'] ?? { result: 'Successfully Upserted' })
- } catch (e: any) {
- logger.error('[server]: Error:', e)
- return res.status(500).send(e.message)
+
+ return upsertedResult['result'] ?? { result: 'Successfully Upserted' }
+ } catch (error) {
+ logger.error('[server]: Error:', error)
+ if (error instanceof Error) {
+ throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, error.message)
+ }
}
}
diff --git a/packages/ui/src/ui-component/button/FlowListMenu.jsx b/packages/ui/src/ui-component/button/FlowListMenu.jsx
index d80231940f8..9c247b2365a 100644
--- a/packages/ui/src/ui-component/button/FlowListMenu.jsx
+++ b/packages/ui/src/ui-component/button/FlowListMenu.jsx
@@ -155,7 +155,7 @@ export default function FlowListMenu({ chatflow, setError, updateFlowsApi }) {
} catch (error) {
setError(error)
enqueueSnackbar({
- message: error.response.data.message,
+ message: typeof error.response.data === 'object' ? error.response.data.message : error.response.data,
options: {
key: new Date().getTime() + Math.random(),
variant: 'error',
@@ -194,7 +194,7 @@ export default function FlowListMenu({ chatflow, setError, updateFlowsApi }) {
} catch (error) {
setError(error)
enqueueSnackbar({
- message: error.response.data.message,
+ message: typeof error.response.data === 'object' ? error.response.data.message : error.response.data,
options: {
key: new Date().getTime() + Math.random(),
variant: 'error',
@@ -226,7 +226,7 @@ export default function FlowListMenu({ chatflow, setError, updateFlowsApi }) {
} catch (error) {
setError(error)
enqueueSnackbar({
- message: error.response.data.message,
+ message: typeof error.response.data === 'object' ? error.response.data.message : error.response.data,
options: {
key: new Date().getTime() + Math.random(),
variant: 'error',
diff --git a/packages/ui/src/ui-component/dialog/ManageScrapedLinksDialog.jsx b/packages/ui/src/ui-component/dialog/ManageScrapedLinksDialog.jsx
index ae9869fa7d7..268c0003c21 100644
--- a/packages/ui/src/ui-component/dialog/ManageScrapedLinksDialog.jsx
+++ b/packages/ui/src/ui-component/dialog/ManageScrapedLinksDialog.jsx
@@ -83,7 +83,7 @@ const ManageScrapedLinksDialog = ({ show, dialogProps, onCancel, onSave }) => {
}
} catch (error) {
enqueueSnackbar({
- message: error.response.data.message,
+ message: typeof error.response.data === 'object' ? error.response.data.message : error.response.data,
options: {
key: new Date().getTime() + Math.random(),
variant: 'error',
diff --git a/packages/ui/src/ui-component/dialog/ViewMessagesDialog.jsx b/packages/ui/src/ui-component/dialog/ViewMessagesDialog.jsx
index fb672e06e5a..6667caf9fa9 100644
--- a/packages/ui/src/ui-component/dialog/ViewMessagesDialog.jsx
+++ b/packages/ui/src/ui-component/dialog/ViewMessagesDialog.jsx
@@ -262,7 +262,7 @@ const ViewMessagesDialog = ({ show, dialogProps, onCancel }) => {
getStatsApi.request(chatflowid) // update stats
} catch (error) {
enqueueSnackbar({
- message: error.response.data.message,
+ message: typeof error.response.data === 'object' ? error.response.data.message : error.response.data,
options: {
key: new Date().getTime() + Math.random(),
variant: 'error',
diff --git a/packages/ui/src/ui-component/extended/AllowedDomains.jsx b/packages/ui/src/ui-component/extended/AllowedDomains.jsx
index 0f37785f9b7..5a5f55b8cc1 100644
--- a/packages/ui/src/ui-component/extended/AllowedDomains.jsx
+++ b/packages/ui/src/ui-component/extended/AllowedDomains.jsx
@@ -70,7 +70,9 @@ const AllowedDomains = ({ dialogProps }) => {
}
} catch (error) {
enqueueSnackbar({
- message: `Failed to save Allowed Origins: ${error.response.data.message}`,
+ message: `Failed to save Allowed Origins: ${
+ typeof error.response.data === 'object' ? error.response.data.message : error.response.data
+ }`,
options: {
key: new Date().getTime() + Math.random(),
variant: 'error',
diff --git a/packages/ui/src/ui-component/extended/AnalyseFlow.jsx b/packages/ui/src/ui-component/extended/AnalyseFlow.jsx
index a31bc6bb61e..6874dc07d69 100644
--- a/packages/ui/src/ui-component/extended/AnalyseFlow.jsx
+++ b/packages/ui/src/ui-component/extended/AnalyseFlow.jsx
@@ -145,7 +145,9 @@ const AnalyseFlow = ({ dialogProps }) => {
}
} catch (error) {
enqueueSnackbar({
- message: `Failed to save Analytic Configuration: ${error.response.data.message}`,
+ message: `Failed to save Analytic Configuration: ${
+ typeof error.response.data === 'object' ? error.response.data.message : error.response.data
+ }`,
options: {
key: new Date().getTime() + Math.random(),
variant: 'error',
diff --git a/packages/ui/src/ui-component/extended/ChatFeedback.jsx b/packages/ui/src/ui-component/extended/ChatFeedback.jsx
index fcebf8f0605..ba769b97bad 100644
--- a/packages/ui/src/ui-component/extended/ChatFeedback.jsx
+++ b/packages/ui/src/ui-component/extended/ChatFeedback.jsx
@@ -60,7 +60,9 @@ const ChatFeedback = ({ dialogProps }) => {
}
} catch (error) {
enqueueSnackbar({
- message: `Failed to save Chat Feedback Settings: ${error.response.data.message}`,
+ message: `Failed to save Chat Feedback Settings: ${
+ typeof error.response.data === 'object' ? error.response.data.message : error.response.data
+ }`,
options: {
key: new Date().getTime() + Math.random(),
variant: 'error',
diff --git a/packages/ui/src/ui-component/extended/RateLimit.jsx b/packages/ui/src/ui-component/extended/RateLimit.jsx
index 5ab8532bd11..3f47667c711 100644
--- a/packages/ui/src/ui-component/extended/RateLimit.jsx
+++ b/packages/ui/src/ui-component/extended/RateLimit.jsx
@@ -74,7 +74,9 @@ const RateLimit = () => {
}
} catch (error) {
enqueueSnackbar({
- message: `Failed to save Rate Limit Configuration: ${error.response.data.message}`,
+ message: `Failed to save Rate Limit Configuration: ${
+ typeof error.response.data === 'object' ? error.response.data.message : error.response.data
+ }`,
options: {
key: new Date().getTime() + Math.random(),
variant: 'error',
diff --git a/packages/ui/src/ui-component/extended/SpeechToText.jsx b/packages/ui/src/ui-component/extended/SpeechToText.jsx
index ba875544cf7..234840ff351 100644
--- a/packages/ui/src/ui-component/extended/SpeechToText.jsx
+++ b/packages/ui/src/ui-component/extended/SpeechToText.jsx
@@ -113,7 +113,9 @@ const SpeechToText = ({ dialogProps }) => {
}
} catch (error) {
enqueueSnackbar({
- message: `Failed to save Speech To Text Configuration: ${error.response.data.message}`,
+ message: `Failed to save Speech To Text Configuration: ${
+ typeof error.response.data === 'object' ? error.response.data.message : error.response.data
+ }`,
options: {
key: new Date().getTime() + Math.random(),
variant: 'error',
diff --git a/packages/ui/src/ui-component/extended/StarterPrompts.jsx b/packages/ui/src/ui-component/extended/StarterPrompts.jsx
index f19f326aa30..89a40642be5 100644
--- a/packages/ui/src/ui-component/extended/StarterPrompts.jsx
+++ b/packages/ui/src/ui-component/extended/StarterPrompts.jsx
@@ -81,7 +81,9 @@ const StarterPrompts = ({ dialogProps }) => {
}
} catch (error) {
enqueueSnackbar({
- message: `Failed to save Conversation Starter Prompts: ${error.response.data.message}`,
+ message: `Failed to save Conversation Starter Prompts: ${
+ typeof error.response.data === 'object' ? error.response.data.message : error.response.data
+ }`,
options: {
key: new Date().getTime() + Math.random(),
variant: 'error',
diff --git a/packages/ui/src/views/apikey/APIKeyDialog.jsx b/packages/ui/src/views/apikey/APIKeyDialog.jsx
index a59bb57f007..6816a31090e 100644
--- a/packages/ui/src/views/apikey/APIKeyDialog.jsx
+++ b/packages/ui/src/views/apikey/APIKeyDialog.jsx
@@ -79,7 +79,9 @@ const APIKeyDialog = ({ show, dialogProps, onCancel, onConfirm, setError }) => {
} catch (error) {
setError(error)
enqueueSnackbar({
- message: `Failed to add new API key: ${error.response.data.message}`,
+ message: `Failed to add new API key: ${
+ typeof error.response.data === 'object' ? error.response.data.message : error.response.data
+ }`,
options: {
key: new Date().getTime() + Math.random(),
variant: 'error',
@@ -116,7 +118,9 @@ const APIKeyDialog = ({ show, dialogProps, onCancel, onConfirm, setError }) => {
} catch (error) {
setError(error)
enqueueSnackbar({
- message: `Failed to save API key: ${error.response.data.message}`,
+ message: `Failed to save API key: ${
+ typeof error.response.data === 'object' ? error.response.data.message : error.response.data
+ }`,
options: {
key: new Date().getTime() + Math.random(),
variant: 'error',
diff --git a/packages/ui/src/views/apikey/index.jsx b/packages/ui/src/views/apikey/index.jsx
index 11d4e032de9..0ecc3a598f4 100644
--- a/packages/ui/src/views/apikey/index.jsx
+++ b/packages/ui/src/views/apikey/index.jsx
@@ -286,7 +286,9 @@ const APIKey = () => {
}
} catch (error) {
enqueueSnackbar({
- message: `Failed to delete API key: ${error.response.data.message}`,
+ message: `Failed to delete API key: ${
+ typeof error.response.data === 'object' ? error.response.data.message : error.response.data
+ }`,
options: {
key: new Date().getTime() + Math.random(),
variant: 'error',
diff --git a/packages/ui/src/views/assistants/AssistantDialog.jsx b/packages/ui/src/views/assistants/AssistantDialog.jsx
index 27f83732c96..802df39dcc5 100644
--- a/packages/ui/src/views/assistants/AssistantDialog.jsx
+++ b/packages/ui/src/views/assistants/AssistantDialog.jsx
@@ -249,7 +249,9 @@ const AssistantDialog = ({ show, dialogProps, onCancel, onConfirm, setError }) =
} catch (error) {
setError(error)
enqueueSnackbar({
- message: `Failed to add new Assistant: ${error.response.data.message}`,
+ message: `Failed to add new Assistant: ${
+ typeof error.response.data === 'object' ? error.response.data.message : error.response.data
+ }`,
options: {
key: new Date().getTime() + Math.random(),
variant: 'error',
@@ -303,7 +305,9 @@ const AssistantDialog = ({ show, dialogProps, onCancel, onConfirm, setError }) =
} catch (error) {
setError(error)
enqueueSnackbar({
- message: `Failed to save Assistant: ${error.response.data.message}`,
+ message: `Failed to save Assistant: ${
+ typeof error.response.data === 'object' ? error.response.data.message : error.response.data
+ }`,
options: {
key: new Date().getTime() + Math.random(),
variant: 'error',
@@ -343,7 +347,9 @@ const AssistantDialog = ({ show, dialogProps, onCancel, onConfirm, setError }) =
} catch (error) {
setError(error)
enqueueSnackbar({
- message: `Failed to sync Assistant: ${error.response.data.message}`,
+ message: `Failed to sync Assistant: ${
+ typeof error.response.data === 'object' ? error.response.data.message : error.response.data
+ }`,
options: {
key: new Date().getTime() + Math.random(),
variant: 'error',
@@ -390,7 +396,9 @@ const AssistantDialog = ({ show, dialogProps, onCancel, onConfirm, setError }) =
} catch (error) {
setError(error)
enqueueSnackbar({
- message: `Failed to delete Assistant: ${error.response.data.message}`,
+ message: `Failed to delete Assistant: ${
+ typeof error.response.data === 'object' ? error.response.data.message : error.response.data
+ }`,
options: {
key: new Date().getTime() + Math.random(),
variant: 'error',
diff --git a/packages/ui/src/views/canvas/index.jsx b/packages/ui/src/views/canvas/index.jsx
index 0e690218a02..c7a5ff016ab 100644
--- a/packages/ui/src/views/canvas/index.jsx
+++ b/packages/ui/src/views/canvas/index.jsx
@@ -173,7 +173,7 @@ const Canvas = () => {
navigate('/')
} catch (error) {
enqueueSnackbar({
- message: error.response.data.message,
+ message: typeof error.response.data === 'object' ? error.response.data.message : error.response.data,
options: {
key: new Date().getTime() + Math.random(),
variant: 'error',
diff --git a/packages/ui/src/views/chatflows/ShareChatbot.jsx b/packages/ui/src/views/chatflows/ShareChatbot.jsx
index 35003594ce9..a9ecc71bdf9 100644
--- a/packages/ui/src/views/chatflows/ShareChatbot.jsx
+++ b/packages/ui/src/views/chatflows/ShareChatbot.jsx
@@ -162,7 +162,9 @@ const ShareChatbot = ({ isSessionMemory }) => {
}
} catch (error) {
enqueueSnackbar({
- message: `Failed to save Chatbot Configuration: ${error.response.data.message}`,
+ message: `Failed to save Chatbot Configuration: ${
+ typeof error.response.data === 'object' ? error.response.data.message : error.response.data
+ }`,
options: {
key: new Date().getTime() + Math.random(),
variant: 'error',
@@ -197,7 +199,9 @@ const ShareChatbot = ({ isSessionMemory }) => {
}
} catch (error) {
enqueueSnackbar({
- message: `Failed to save Chatbot Configuration: ${error.response.data.message}`,
+ message: `Failed to save Chatbot Configuration: ${
+ typeof error.response.data === 'object' ? error.response.data.message : error.response.data
+ }`,
options: {
key: new Date().getTime() + Math.random(),
variant: 'error',
diff --git a/packages/ui/src/views/chatmessage/ChatPopUp.jsx b/packages/ui/src/views/chatmessage/ChatPopUp.jsx
index b592643b0ae..d54478db260 100644
--- a/packages/ui/src/views/chatmessage/ChatPopUp.jsx
+++ b/packages/ui/src/views/chatmessage/ChatPopUp.jsx
@@ -106,7 +106,7 @@ export const ChatPopUp = ({ chatflowid }) => {
})
} catch (error) {
enqueueSnackbar({
- message: error.response.data.message,
+ message: typeof error.response.data === 'object' ? error.response.data.message : error.response.data,
options: {
key: new Date().getTime() + Math.random(),
variant: 'error',
diff --git a/packages/ui/src/views/credentials/AddEditCredentialDialog.jsx b/packages/ui/src/views/credentials/AddEditCredentialDialog.jsx
index 7d36826fa64..dfdfe9af261 100644
--- a/packages/ui/src/views/credentials/AddEditCredentialDialog.jsx
+++ b/packages/ui/src/views/credentials/AddEditCredentialDialog.jsx
@@ -134,7 +134,9 @@ const AddEditCredentialDialog = ({ show, dialogProps, onCancel, onConfirm, setEr
} catch (error) {
setError(error)
enqueueSnackbar({
- message: `Failed to add new Credential: ${error.response.data.message}`,
+ message: `Failed to add new Credential: ${
+ typeof error.response.data === 'object' ? error.response.data.message : error.response.data
+ }`,
options: {
key: new Date().getTime() + Math.random(),
variant: 'error',
@@ -184,7 +186,9 @@ const AddEditCredentialDialog = ({ show, dialogProps, onCancel, onConfirm, setEr
} catch (error) {
setError(error)
enqueueSnackbar({
- message: `Failed to save Credential: ${error.response.data.message}`,
+ message: `Failed to save Credential: ${
+ typeof error.response.data === 'object' ? error.response.data.message : error.response.data
+ }`,
options: {
key: new Date().getTime() + Math.random(),
variant: 'error',
diff --git a/packages/ui/src/views/credentials/index.jsx b/packages/ui/src/views/credentials/index.jsx
index dbe07960b68..13413ec799b 100644
--- a/packages/ui/src/views/credentials/index.jsx
+++ b/packages/ui/src/views/credentials/index.jsx
@@ -162,7 +162,9 @@ const Credentials = () => {
}
} catch (error) {
enqueueSnackbar({
- message: `Failed to delete Credential: ${error.response.data.message}`,
+ message: `Failed to delete Credential: ${
+ typeof error.response.data === 'object' ? error.response.data.message : error.response.data
+ }`,
options: {
key: new Date().getTime() + Math.random(),
variant: 'error',
diff --git a/packages/ui/src/views/tools/ToolDialog.jsx b/packages/ui/src/views/tools/ToolDialog.jsx
index a94ad494da3..43d53c32872 100644
--- a/packages/ui/src/views/tools/ToolDialog.jsx
+++ b/packages/ui/src/views/tools/ToolDialog.jsx
@@ -233,7 +233,9 @@ const ToolDialog = ({ show, dialogProps, onUseTemplate, onCancel, onConfirm, set
}
} catch (error) {
enqueueSnackbar({
- message: `Failed to export Tool: ${error.response.data.message}`,
+ message: `Failed to export Tool: ${
+ typeof error.response.data === 'object' ? error.response.data.message : error.response.data
+ }`,
options: {
key: new Date().getTime() + Math.random(),
variant: 'error',
@@ -277,7 +279,9 @@ const ToolDialog = ({ show, dialogProps, onUseTemplate, onCancel, onConfirm, set
}
} catch (error) {
enqueueSnackbar({
- message: `Failed to add new Tool: ${error.response.data.message}`,
+ message: `Failed to add new Tool: ${
+ typeof error.response.data === 'object' ? error.response.data.message : error.response.data
+ }`,
options: {
key: new Date().getTime() + Math.random(),
variant: 'error',
@@ -319,7 +323,9 @@ const ToolDialog = ({ show, dialogProps, onUseTemplate, onCancel, onConfirm, set
}
} catch (error) {
enqueueSnackbar({
- message: `Failed to save Tool: ${error.response.data.message}`,
+ message: `Failed to save Tool: ${
+ typeof error.response.data === 'object' ? error.response.data.message : error.response.data
+ }`,
options: {
key: new Date().getTime() + Math.random(),
variant: 'error',
@@ -364,7 +370,9 @@ const ToolDialog = ({ show, dialogProps, onUseTemplate, onCancel, onConfirm, set
}
} catch (error) {
enqueueSnackbar({
- message: `Failed to delete Tool: ${error.response.data.message}`,
+ message: `Failed to delete Tool: ${
+ typeof error.response.data === 'object' ? error.response.data.message : error.response.data
+ }`,
options: {
key: new Date().getTime() + Math.random(),
variant: 'error',
diff --git a/packages/ui/src/views/variables/AddEditVariableDialog.jsx b/packages/ui/src/views/variables/AddEditVariableDialog.jsx
index cf30249746f..c26c7d35f29 100644
--- a/packages/ui/src/views/variables/AddEditVariableDialog.jsx
+++ b/packages/ui/src/views/variables/AddEditVariableDialog.jsx
@@ -113,7 +113,9 @@ const AddEditVariableDialog = ({ show, dialogProps, onCancel, onConfirm, setErro
} catch (err) {
setError(err)
enqueueSnackbar({
- message: `Failed to add new Variable: ${error.response.data.message}`,
+ message: `Failed to add new Variable: ${
+ typeof error.response.data === 'object' ? error.response.data.message : error.response.data
+ }`,
options: {
key: new Date().getTime() + Math.random(),
variant: 'error',
@@ -156,7 +158,9 @@ const AddEditVariableDialog = ({ show, dialogProps, onCancel, onConfirm, setErro
} catch (error) {
setError(err)
enqueueSnackbar({
- message: `Failed to save Variable: ${error.response.data.message}`,
+ message: `Failed to save Variable: ${
+ typeof error.response.data === 'object' ? error.response.data.message : error.response.data
+ }`,
options: {
key: new Date().getTime() + Math.random(),
variant: 'error',
diff --git a/packages/ui/src/views/variables/index.jsx b/packages/ui/src/views/variables/index.jsx
index 280711e9a6f..c4436c94407 100644
--- a/packages/ui/src/views/variables/index.jsx
+++ b/packages/ui/src/views/variables/index.jsx
@@ -149,7 +149,9 @@ const Variables = () => {
}
} catch (error) {
enqueueSnackbar({
- message: `Failed to delete Variable: ${error.response.data.message}`,
+ message: `Failed to delete Variable: ${
+ typeof error.response.data === 'object' ? error.response.data.message : error.response.data
+ }`,
options: {
key: new Date().getTime() + Math.random(),
variant: 'error',
diff --git a/packages/ui/src/views/vectorstore/UpsertHistoryDialog.jsx b/packages/ui/src/views/vectorstore/UpsertHistoryDialog.jsx
index 5c976eceb43..1d4b6aa28fc 100644
--- a/packages/ui/src/views/vectorstore/UpsertHistoryDialog.jsx
+++ b/packages/ui/src/views/vectorstore/UpsertHistoryDialog.jsx
@@ -259,7 +259,9 @@ const UpsertHistoryDialog = ({ show, dialogProps, onCancel }) => {
setSelected([])
} catch (error) {
enqueueSnackbar({
- message: 'Error deleting upsert history',
+ message: `Failed to delete Upsert History: ${
+ typeof error.response.data === 'object' ? error.response.data.message : error.response.data
+ }`,
options: {
key: new Date().getTime() + Math.random(),
variant: 'error',
diff --git a/packages/ui/src/views/vectorstore/VectorStoreDialog.jsx b/packages/ui/src/views/vectorstore/VectorStoreDialog.jsx
index 059f0c6ee96..18110c48fd9 100644
--- a/packages/ui/src/views/vectorstore/VectorStoreDialog.jsx
+++ b/packages/ui/src/views/vectorstore/VectorStoreDialog.jsx
@@ -293,7 +293,7 @@ query(formData).then((response) => {
if (res && res.data && typeof res.data === 'object') onIndexResult(res.data)
} catch (error) {
enqueueSnackbar({
- message: error.response.data.message,
+ message: typeof error.response.data === 'object' ? error.response.data.message : error.response.data,
options: {
key: new Date().getTime() + Math.random(),
variant: 'error',