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 componentsCredentialsService from '../../services/components-credentials'
|
||||
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
|
||||
import { StatusCodes } from 'http-status-codes'
|
||||
|
||||
// Get all component credentials
|
||||
const getAllComponentsCredentials = async (req: Request, res: Response, next: NextFunction) => {
|
||||
@@ -14,8 +16,11 @@ const getAllComponentsCredentials = async (req: Request, res: Response, next: Ne
|
||||
// Get component credential via name
|
||||
const getComponentByName = async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
if (typeof req.params.name === 'undefined' || req.params.name === '') {
|
||||
throw new Error(`Error: componentsCredentialsController.getComponentByName - name not provided!`)
|
||||
if (typeof req.params === 'undefined' || !req.params.name) {
|
||||
throw new InternalFlowiseError(
|
||||
StatusCodes.PRECONDITION_FAILED,
|
||||
`Error: componentsCredentialsController.getComponentByName - name not provided!`
|
||||
)
|
||||
}
|
||||
const apiResponse = await componentsCredentialsService.getComponentByName(req.params.name)
|
||||
return res.json(apiResponse)
|
||||
@@ -27,8 +32,11 @@ const getComponentByName = async (req: Request, res: Response, next: NextFunctio
|
||||
// Returns specific component credential icon via name
|
||||
const getSingleComponentsCredentialIcon = async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
if (typeof req.params.name === 'undefined' || req.params.name === '') {
|
||||
throw new Error(`Error: componentsCredentialsController.getSingleComponentsCredentialIcon - name not provided!`)
|
||||
if (typeof req.params === 'undefined' || !req.params.name) {
|
||||
throw new InternalFlowiseError(
|
||||
StatusCodes.PRECONDITION_FAILED,
|
||||
`Error: componentsCredentialsController.getSingleComponentsCredentialIcon - name not provided!`
|
||||
)
|
||||
}
|
||||
const apiResponse = await componentsCredentialsService.getSingleComponentsCredentialIcon(req.params.name)
|
||||
return res.sendFile(apiResponse)
|
||||
|
||||
Reference in New Issue
Block a user