mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 19:00:59 +03:00
Bugfix/Correctly throw 401 error when unauthorized (#2626)
correctly throw 401 error when unauthorized
This commit is contained in:
@@ -417,7 +417,11 @@ export const utilBuildChatflow = async (req: Request, socketIO?: Server, isInter
|
||||
return result
|
||||
} catch (e) {
|
||||
logger.error('[server]: Error:', e)
|
||||
throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, getErrorMessage(e))
|
||||
if (e instanceof InternalFlowiseError && e.statusCode === StatusCodes.UNAUTHORIZED) {
|
||||
throw e
|
||||
} else {
|
||||
throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, getErrorMessage(e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ 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'
|
||||
|
||||
/**
|
||||
* Upsert documents
|
||||
@@ -163,10 +164,12 @@ export const upsertVector = async (req: Request, isInternal: boolean = false) =>
|
||||
})
|
||||
|
||||
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)
|
||||
} catch (e) {
|
||||
logger.error('[server]: Error:', e)
|
||||
if (e instanceof InternalFlowiseError && e.statusCode === StatusCodes.UNAUTHORIZED) {
|
||||
throw e
|
||||
} else {
|
||||
throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, getErrorMessage(e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user