mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 13:00:56 +03:00
Chore/consistent services and error handlers (#2101)
* Update index.ts * Update buildChatflow.ts * Update index.ts * Update index.ts * Update index.ts * Update index.ts * Update index.ts * Update index.ts * Update index.ts * Update index.ts * Consistency * Rename ApiError to InternalServerError * Use InternalFlowiseError in controllers * Use InternalFlowiseError in services * Catch routes without preconditioned parameters * Reconfigure the route precondition checks * Fix router precondition checks * cleanup status codes, get proper error messages --------- Co-authored-by: Henry <hzj94@hotmail.com>
This commit is contained in:
committed by
GitHub
parent
024b2ad22e
commit
d7194e8aaa
@@ -1,5 +1,7 @@
|
||||
import { Request, Response, NextFunction } from 'express'
|
||||
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
|
||||
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
|
||||
import { StatusCodes } from 'http-status-codes'
|
||||
|
||||
// Returns specific component node icon via name
|
||||
const getSingleNodeIcon = async (req: Request, res: Response, next: NextFunction) => {
|
||||
@@ -8,17 +10,26 @@ const getSingleNodeIcon = async (req: Request, res: Response, next: NextFunction
|
||||
if (Object.prototype.hasOwnProperty.call(appServer.nodesPool.componentNodes, req.params.name)) {
|
||||
const nodeInstance = appServer.nodesPool.componentNodes[req.params.name]
|
||||
if (nodeInstance.icon === undefined) {
|
||||
throw new Error(`Error: nodeIconController.getSingleNodeIcon - Node ${req.params.name} icon not found`)
|
||||
throw new InternalFlowiseError(
|
||||
StatusCodes.NOT_FOUND,
|
||||
`Error: nodeIconController.getSingleNodeIcon - Node ${req.params.name} icon not found`
|
||||
)
|
||||
}
|
||||
|
||||
if (nodeInstance.icon.endsWith('.svg') || nodeInstance.icon.endsWith('.png') || nodeInstance.icon.endsWith('.jpg')) {
|
||||
const filepath = nodeInstance.icon
|
||||
res.sendFile(filepath)
|
||||
} else {
|
||||
throw new Error(`Error: nodeIconController.getSingleNodeIcon - Node ${req.params.name} icon is missing icon`)
|
||||
throw new InternalFlowiseError(
|
||||
StatusCodes.PRECONDITION_FAILED,
|
||||
`Error: nodeIconController.getSingleNodeIcon - Node ${req.params.name} icon is missing icon`
|
||||
)
|
||||
}
|
||||
} else {
|
||||
throw new Error(`Error: nodeIconController.getSingleNodeIcon - Node ${req.params.name} not found`)
|
||||
throw new InternalFlowiseError(
|
||||
StatusCodes.NOT_FOUND,
|
||||
`Error: nodeIconController.getSingleNodeIcon - Node ${req.params.name} not found`
|
||||
)
|
||||
}
|
||||
} catch (error) {
|
||||
next(error)
|
||||
|
||||
Reference in New Issue
Block a user