@@ -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,8 @@ 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 (500 , detail = "Internal error occurred during LDAP user creation." )
280281
281282 user = Auths .authenticate_user_by_trusted_header (email )
282283
@@ -312,12 +313,10 @@ async def ldap_auth(request: Request, response: Response, form_data: LdapForm):
312313 else :
313314 raise HTTPException (400 , detail = ERROR_MESSAGES .INVALID_CRED )
314315 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- )
316+ raise HTTPException (400 , "User record mismatch." )
319317 except Exception as e :
320- raise HTTPException (400 , detail = str (e ))
318+ log .error (f"LDAP authentication error: { str (e )} " )
319+ raise HTTPException (400 , detail = "LDAP authentication failed." )
321320
322321
323322############################
@@ -519,7 +518,8 @@ async def signup(request: Request, response: Response, form_data: SignupForm):
519518 else :
520519 raise HTTPException (500 , detail = ERROR_MESSAGES .CREATE_USER_ERROR )
521520 except Exception as err :
522- raise HTTPException (500 , detail = ERROR_MESSAGES .DEFAULT (err ))
521+ log .error (f"Signup error: { str (err )} " )
522+ raise HTTPException (500 , detail = "An internal error occurred during signup." )
523523
524524
525525@router .get ("/signout" )
@@ -547,7 +547,8 @@ async def signout(request: Request, response: Response):
547547 detail = "Failed to fetch OpenID configuration" ,
548548 )
549549 except Exception as e :
550- raise HTTPException (status_code = 500 , detail = str (e ))
550+ log .error (f"OpenID signout error: { str (e )} " )
551+ raise HTTPException (status_code = 500 , detail = "Failed to sign out from the OpenID provider." )
551552
552553 return {"status" : True }
553554
@@ -591,7 +592,8 @@ async def add_user(form_data: AddUserForm, user=Depends(get_admin_user)):
591592 else :
592593 raise HTTPException (500 , detail = ERROR_MESSAGES .CREATE_USER_ERROR )
593594 except Exception as err :
594- raise HTTPException (500 , detail = ERROR_MESSAGES .DEFAULT (err ))
595+ log .error (f"Add user error: { str (err )} " )
596+ raise HTTPException (500 , detail = "An internal error occurred while adding the user." )
595597
596598
597599############################
0 commit comments