Skip to content

Commit 48d690c

Browse files
authored
Merge pull request open-webui#12481 from gaby/generic-errors
fix: Improve auth error messages
2 parents 69c68df + 3245504 commit 48d690c

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

backend/open_webui/retrieval/utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,12 @@ def process_query(collection_name, query):
322322

323323
# Prepare tasks for all collections and queries
324324
# Avoid running any tasks for collections that failed to fetch data (have assigned None)
325-
tasks = [(cn, q) for cn in collection_names if collection_results[cn] is not None for q in queries]
325+
tasks = [
326+
(cn, q)
327+
for cn in collection_names
328+
if collection_results[cn] is not None
329+
for q in queries
330+
]
326331

327332
with ThreadPoolExecutor() as executor:
328333
future_results = [executor.submit(process_query, cn, q) for cn, q in tasks]

backend/open_webui/routers/auths.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ async def ldap_auth(request: Request, response: Response, form_data: LdapForm):
194194
ciphers=LDAP_CIPHERS,
195195
)
196196
except Exception as e:
197-
log.error(f"An error occurred on TLS: {str(e)}")
198-
raise HTTPException(400, detail=str(e))
197+
log.error(f"TLS configuration error: {str(e)}")
198+
raise HTTPException(400, detail="Failed to configure TLS for LDAP connection.")
199199

200200
try:
201201
server = Server(
@@ -232,7 +232,7 @@ async def ldap_auth(request: Request, response: Response, form_data: LdapForm):
232232
username = str(entry[f"{LDAP_ATTRIBUTE_FOR_USERNAME}"]).lower()
233233
email = str(entry[f"{LDAP_ATTRIBUTE_FOR_MAIL}"])
234234
if not email or email == "" or email == "[]":
235-
raise HTTPException(400, f"User {form_data.user} does not have email.")
235+
raise HTTPException(400, "User does not have a valid email address.")
236236
else:
237237
email = email.lower()
238238

@@ -248,7 +248,7 @@ async def ldap_auth(request: Request, response: Response, form_data: LdapForm):
248248
authentication="SIMPLE",
249249
)
250250
if not connection_user.bind():
251-
raise HTTPException(400, f"Authentication failed for {form_data.user}")
251+
raise HTTPException(400, "Authentication failed.")
252252

253253
user = Users.get_user_by_email(email)
254254
if not user:
@@ -276,7 +276,10 @@ async def ldap_auth(request: Request, response: Response, form_data: LdapForm):
276276
except HTTPException:
277277
raise
278278
except Exception as err:
279-
raise HTTPException(500, detail=ERROR_MESSAGES.DEFAULT(err))
279+
log.error(f"LDAP user creation error: {str(err)}")
280+
raise HTTPException(
281+
500, detail="Internal error occurred during LDAP user creation."
282+
)
280283

281284
user = Auths.authenticate_user_by_trusted_header(email)
282285

@@ -312,12 +315,10 @@ async def ldap_auth(request: Request, response: Response, form_data: LdapForm):
312315
else:
313316
raise HTTPException(400, detail=ERROR_MESSAGES.INVALID_CRED)
314317
else:
315-
raise HTTPException(
316-
400,
317-
f"User {form_data.user} does not match the record. Search result: {str(entry[f'{LDAP_ATTRIBUTE_FOR_USERNAME}'])}",
318-
)
318+
raise HTTPException(400, "User record mismatch.")
319319
except Exception as e:
320-
raise HTTPException(400, detail=str(e))
320+
log.error(f"LDAP authentication error: {str(e)}")
321+
raise HTTPException(400, detail="LDAP authentication failed.")
321322

322323

323324
############################
@@ -519,7 +520,8 @@ async def signup(request: Request, response: Response, form_data: SignupForm):
519520
else:
520521
raise HTTPException(500, detail=ERROR_MESSAGES.CREATE_USER_ERROR)
521522
except Exception as err:
522-
raise HTTPException(500, detail=ERROR_MESSAGES.DEFAULT(err))
523+
log.error(f"Signup error: {str(err)}")
524+
raise HTTPException(500, detail="An internal error occurred during signup.")
523525

524526

525527
@router.get("/signout")
@@ -547,7 +549,11 @@ async def signout(request: Request, response: Response):
547549
detail="Failed to fetch OpenID configuration",
548550
)
549551
except Exception as e:
550-
raise HTTPException(status_code=500, detail=str(e))
552+
log.error(f"OpenID signout error: {str(e)}")
553+
raise HTTPException(
554+
status_code=500,
555+
detail="Failed to sign out from the OpenID provider.",
556+
)
551557

552558
return {"status": True}
553559

@@ -591,7 +597,10 @@ async def add_user(form_data: AddUserForm, user=Depends(get_admin_user)):
591597
else:
592598
raise HTTPException(500, detail=ERROR_MESSAGES.CREATE_USER_ERROR)
593599
except Exception as err:
594-
raise HTTPException(500, detail=ERROR_MESSAGES.DEFAULT(err))
600+
log.error(f"Add user error: {str(err)}")
601+
raise HTTPException(
602+
500, detail="An internal error occurred while adding the user."
603+
)
595604

596605

597606
############################

0 commit comments

Comments
 (0)