Skip to content

Commit

Permalink
Merge pull request Onlineberatung#489 from Onlineberatung/chore_impro…
Browse files Browse the repository at this point in the history
…ve_logging_during_session_init

chore: improve logging during session init
  • Loading branch information
mebo4b authored Sep 8, 2022
2 parents 5da7851 + 2b89159 commit 4a0feb4
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static de.caritas.cob.userservice.api.helper.SessionDataProvider.fromUserDTO;
import static java.util.Objects.isNull;
import static java.util.Objects.nonNull;
import static java.util.Objects.requireNonNull;
import static org.apache.commons.lang3.BooleanUtils.isTrue;

Expand Down Expand Up @@ -130,11 +131,14 @@ private void initializeMonitoring(
}

private Session initializeSession(UserDTO userDTO, User user, AgencyDTO agencyDTO) {
var sessionData = fromUserDTO(userDTO);
var isTeaming = isTrue(agencyDTO.getTeamAgency());
boolean initialized = false;

try {
var session =
sessionService.initializeSession(user, userDTO, isTrue(agencyDTO.getTeamAgency()));
sessionDataService.saveSessionData(session, fromUserDTO(userDTO));
var session = sessionService.initializeSession(user, userDTO, isTeaming);
initialized = nonNull(session) && nonNull(session.getId());
sessionDataService.saveSessionData(session, sessionData);

return session;
} catch (Exception ex) {
Expand All @@ -145,9 +149,9 @@ private Session initializeSession(UserDTO userDTO, User user, AgencyDTO agencyDT
.rollBackUserAccount(Boolean.parseBoolean(userDTO.getTermsAccepted()))
.build());

throw new InternalServerErrorException(
String.format(
"Could not create session for user %s. %s", user.getUsername(), ex.getMessage()));
var stepWord = initialized ? "save session data" : "initialize session";
var message = String.format("Could not %s for user %s.", stepWord, user.getUsername());
throw new InternalServerErrorException(message, ex);
}
}

Expand Down

0 comments on commit 4a0feb4

Please sign in to comment.