refac
This commit is contained in:
1 parent
ee5de69e37
commit
0883638027
7 files changed
+86
-43
No files matched your search
@@ -22,7 +22,6 @@ from open_webui.models.functions import (
|
||||
FunctionWithValvesModel,
|
||||
)
|
||||
from open_webui.utils.auth import get_admin_user, get_verified_user
|
||||
from open_webui.utils.errors import error_detail
|
||||
from open_webui.utils.plugin import (
|
||||
get_functions_cache,
|
||||
get_function_module_from_cache,
|
||||
@@ -133,8 +132,13 @@ async def load_function_from_url(request: Request, form_data: LoadUrlForm, user=
|
||||
'name': function_name,
|
||||
'content': data,
|
||||
}
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=error_detail(e, 'Error fetching function'))
|
||||
raise HTTPException(
|
||||
status_code=500,
|
||||
detail=ERROR_MESSAGES.DEFAULT(e, 'Error fetching function'),
|
||||
)
|
||||
|
||||
|
||||
############################
|
||||
@@ -174,7 +178,7 @@ async def sync_functions(
|
||||
log.exception(f'Failed to load a function: {e}')
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=error_detail(e, 'Error loading function'),
|
||||
detail=ERROR_MESSAGES.DEFAULT(e, 'Error loading function'),
|
||||
)
|
||||
|
||||
|
||||
@@ -233,11 +237,13 @@ async def create_new_function(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=ERROR_MESSAGES.DEFAULT('Error creating function'),
|
||||
)
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
log.exception(f'Failed to create a new function: {e}')
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=error_detail(e, 'Error creating function'),
|
||||
detail=ERROR_MESSAGES.DEFAULT(e, 'Error creating function'),
|
||||
)
|
||||
else:
|
||||
raise HTTPException(
|
||||
@@ -382,10 +388,12 @@ async def update_function_by_id(
|
||||
detail=ERROR_MESSAGES.DEFAULT('Error updating function'),
|
||||
)
|
||||
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=error_detail(e, 'Error updating function'),
|
||||
detail=ERROR_MESSAGES.DEFAULT(e, 'Error updating function'),
|
||||
)
|
||||
|
||||
|
||||
@@ -433,7 +441,7 @@ async def get_function_valves_by_id(
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=error_detail(e, 'Error getting function valves'),
|
||||
detail=ERROR_MESSAGES.DEFAULT(e, 'Error getting function valves'),
|
||||
)
|
||||
else:
|
||||
raise HTTPException(
|
||||
@@ -509,7 +517,7 @@ async def update_function_valves_by_id(
|
||||
log.exception(f'Error updating function values by id {id}: {e}')
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=error_detail(e, 'Error updating function valves'),
|
||||
detail=ERROR_MESSAGES.DEFAULT(e, 'Error updating function valves'),
|
||||
)
|
||||
else:
|
||||
raise HTTPException(
|
||||
@@ -541,7 +549,7 @@ async def get_function_user_valves_by_id(
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=error_detail(e, 'Error getting function user valves'),
|
||||
detail=ERROR_MESSAGES.DEFAULT(e, 'Error getting function user valves'),
|
||||
)
|
||||
else:
|
||||
raise HTTPException(
|
||||
@@ -608,7 +616,7 @@ async def update_function_user_valves_by_id(
|
||||
log.exception(f'Error updating function user valves by id {id}: {e}')
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=error_detail(e, 'Error updating function user valves'),
|
||||
detail=ERROR_MESSAGES.DEFAULT(e, 'Error updating function user valves'),
|
||||
)
|
||||
else:
|
||||
raise HTTPException(
|
||||
|
||||
Reference in new issue
Block a user