mirror of
https://github.com/open-webui/open-webui
synced 2025-04-30 03:02:06 +00:00
Merge pull request #12481 from gaby/generic-errors
fix: Improve auth error messages
This commit is contained in:
commit
48d690c55d
@ -322,7 +322,12 @@ def query_collection_with_hybrid_search(
|
|||||||
|
|
||||||
# Prepare tasks for all collections and queries
|
# Prepare tasks for all collections and queries
|
||||||
# Avoid running any tasks for collections that failed to fetch data (have assigned None)
|
# Avoid running any tasks for collections that failed to fetch data (have assigned None)
|
||||||
tasks = [(cn, q) for cn in collection_names if collection_results[cn] is not None for q in queries]
|
tasks = [
|
||||||
|
(cn, q)
|
||||||
|
for cn in collection_names
|
||||||
|
if collection_results[cn] is not None
|
||||||
|
for q in queries
|
||||||
|
]
|
||||||
|
|
||||||
with ThreadPoolExecutor() as executor:
|
with ThreadPoolExecutor() as executor:
|
||||||
future_results = [executor.submit(process_query, cn, q) for cn, q in tasks]
|
future_results = [executor.submit(process_query, cn, q) for cn, q in tasks]
|
||||||
|
@ -194,8 +194,8 @@ async def ldap_auth(request: Request, response: Response, form_data: LdapForm):
|
|||||||
ciphers=LDAP_CIPHERS,
|
ciphers=LDAP_CIPHERS,
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.error(f"An error occurred on TLS: {str(e)}")
|
log.error(f"TLS configuration error: {str(e)}")
|
||||||
raise HTTPException(400, detail=str(e))
|
raise HTTPException(400, detail="Failed to configure TLS for LDAP connection.")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
server = Server(
|
server = Server(
|
||||||
@ -232,7 +232,7 @@ async def ldap_auth(request: Request, response: Response, form_data: LdapForm):
|
|||||||
username = str(entry[f"{LDAP_ATTRIBUTE_FOR_USERNAME}"]).lower()
|
username = str(entry[f"{LDAP_ATTRIBUTE_FOR_USERNAME}"]).lower()
|
||||||
email = str(entry[f"{LDAP_ATTRIBUTE_FOR_MAIL}"])
|
email = str(entry[f"{LDAP_ATTRIBUTE_FOR_MAIL}"])
|
||||||
if not email or email == "" or email == "[]":
|
if not email or email == "" or email == "[]":
|
||||||
raise HTTPException(400, f"User {form_data.user} does not have email.")
|
raise HTTPException(400, "User does not have a valid email address.")
|
||||||
else:
|
else:
|
||||||
email = email.lower()
|
email = email.lower()
|
||||||
|
|
||||||
@ -248,7 +248,7 @@ async def ldap_auth(request: Request, response: Response, form_data: LdapForm):
|
|||||||
authentication="SIMPLE",
|
authentication="SIMPLE",
|
||||||
)
|
)
|
||||||
if not connection_user.bind():
|
if not connection_user.bind():
|
||||||
raise HTTPException(400, f"Authentication failed for {form_data.user}")
|
raise HTTPException(400, "Authentication failed.")
|
||||||
|
|
||||||
user = Users.get_user_by_email(email)
|
user = Users.get_user_by_email(email)
|
||||||
if not user:
|
if not user:
|
||||||
@ -276,7 +276,10 @@ async def ldap_auth(request: Request, response: Response, form_data: LdapForm):
|
|||||||
except HTTPException:
|
except HTTPException:
|
||||||
raise
|
raise
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
raise HTTPException(500, detail=ERROR_MESSAGES.DEFAULT(err))
|
log.error(f"LDAP user creation error: {str(err)}")
|
||||||
|
raise HTTPException(
|
||||||
|
500, detail="Internal error occurred during LDAP user creation."
|
||||||
|
)
|
||||||
|
|
||||||
user = Auths.authenticate_user_by_trusted_header(email)
|
user = Auths.authenticate_user_by_trusted_header(email)
|
||||||
|
|
||||||
@ -312,12 +315,10 @@ async def ldap_auth(request: Request, response: Response, form_data: LdapForm):
|
|||||||
else:
|
else:
|
||||||
raise HTTPException(400, detail=ERROR_MESSAGES.INVALID_CRED)
|
raise HTTPException(400, detail=ERROR_MESSAGES.INVALID_CRED)
|
||||||
else:
|
else:
|
||||||
raise HTTPException(
|
raise HTTPException(400, "User record mismatch.")
|
||||||
400,
|
|
||||||
f"User {form_data.user} does not match the record. Search result: {str(entry[f'{LDAP_ATTRIBUTE_FOR_USERNAME}'])}",
|
|
||||||
)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise HTTPException(400, detail=str(e))
|
log.error(f"LDAP authentication error: {str(e)}")
|
||||||
|
raise HTTPException(400, detail="LDAP authentication failed.")
|
||||||
|
|
||||||
|
|
||||||
############################
|
############################
|
||||||
@ -519,7 +520,8 @@ async def signup(request: Request, response: Response, form_data: SignupForm):
|
|||||||
else:
|
else:
|
||||||
raise HTTPException(500, detail=ERROR_MESSAGES.CREATE_USER_ERROR)
|
raise HTTPException(500, detail=ERROR_MESSAGES.CREATE_USER_ERROR)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
raise HTTPException(500, detail=ERROR_MESSAGES.DEFAULT(err))
|
log.error(f"Signup error: {str(err)}")
|
||||||
|
raise HTTPException(500, detail="An internal error occurred during signup.")
|
||||||
|
|
||||||
|
|
||||||
@router.get("/signout")
|
@router.get("/signout")
|
||||||
@ -547,7 +549,11 @@ async def signout(request: Request, response: Response):
|
|||||||
detail="Failed to fetch OpenID configuration",
|
detail="Failed to fetch OpenID configuration",
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise HTTPException(status_code=500, detail=str(e))
|
log.error(f"OpenID signout error: {str(e)}")
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=500,
|
||||||
|
detail="Failed to sign out from the OpenID provider.",
|
||||||
|
)
|
||||||
|
|
||||||
return {"status": True}
|
return {"status": True}
|
||||||
|
|
||||||
@ -591,7 +597,10 @@ async def add_user(form_data: AddUserForm, user=Depends(get_admin_user)):
|
|||||||
else:
|
else:
|
||||||
raise HTTPException(500, detail=ERROR_MESSAGES.CREATE_USER_ERROR)
|
raise HTTPException(500, detail=ERROR_MESSAGES.CREATE_USER_ERROR)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
raise HTTPException(500, detail=ERROR_MESSAGES.DEFAULT(err))
|
log.error(f"Add user error: {str(err)}")
|
||||||
|
raise HTTPException(
|
||||||
|
500, detail="An internal error occurred while adding the user."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
############################
|
############################
|
||||||
|
Loading…
Reference in New Issue
Block a user