@@ -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