Chore/consistent services and error handlers (#2101)

* Update index.ts

* Update buildChatflow.ts

* Update index.ts

* Update index.ts

* Update index.ts

* Update index.ts

* Update index.ts

* Update index.ts

* Update index.ts

* Update index.ts

* Consistency

* Rename ApiError to InternalServerError

* Use InternalFlowiseError in controllers

* Use InternalFlowiseError in services

* Catch routes without preconditioned parameters

* Reconfigure the route precondition checks

* Fix router precondition checks

* cleanup status codes, get proper error messages

---------

Co-authored-by: Henry <hzj94@hotmail.com>
This commit is contained in:
Octavian FlowiseAI
2024-04-11 03:11:01 -07:00
committed by GitHub
parent 024b2ad22e
commit d7194e8aaa
98 changed files with 862 additions and 651 deletions
@@ -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)