I have the code block as below. I need to stop after i throw the exceptions in the elseif or else statements and not return the final return statement after the try catch if it goes into the elseif or else statements.
@Override
public Mono<JwToken> login(Account account) throws Exception {
Mono<JwToken> jwtoken = null;
try {
sessionCountL = Integer.valueOf(sessionCount.get().value());
if (sessionCountL < 3 && failedAttempts <3){
Map<String, String> auth = new ConcurrentHashMap<>();
String secretHash = calculateSecretHash;
auth.put("USERNAME", account.getEmail());
auth.put("PASSWORD", account.getPassword());
auth.put("SECRET_HASH", secretHash);
jwtoken = initiateAuth(auth, AuthFlowType.USER_PASSWORD_AUTH)
.map(response -> JwToken.builder().build());
incrementSessionCount(account); //this should be executed if the login is successful, if its not i need to throw an exception
}
else if(sessionCountL>2){
log.info("Active sessions limit reached. Logging out from all devices. Session Count{}",sessionCountL);
logout(account.getEmail());
sessionCountL = 0;
log.info("sessionCount{} updated", sessionCountL);
throw new Exception("Active sessions limit reached. Logged out of all sessions."); //after it throws the exception i want to break out of this XYZ method
}
else{
log.info("failed attempts else statement:");
logout(account.getEmail());
sessionCountL = 0;
log.info("logged out of all active sessions and sessionCount updated to {}", sessionCountL);
lockAccount(account.getEmail());
failedAttempts = 0;
log.info("Account is locked. Failed attempts count is updated to {}", failedAttempts);
throw new Exception("Too many failed login attempts. Account is locked");//after it throws the exception i want to break out of this XYZ method
}
}
catch(Exception e) {
failedAttempts = +1;
log.info("Main try catch-InitiateAuth error. Failed attempts updated to:{}",failedAttempts);
e.printStackTrace();
}
log.info("Final return statement JwToken:{}",jwtoken);
return jwtoken;
}
将 return 语句移到 if 条件中 then
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.