Skip to content

Commit

Permalink
Change the SessionManagementException handling
Browse files Browse the repository at this point in the history
  • Loading branch information
pamodaaw committed Jul 25, 2019
1 parent 282af6c commit 6c814e7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public String getDescription() {
@Override
public String toString() {

return code + " | " + message;
return getCode() + " | " + message;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,6 @@
<artifactId>spring-web</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ public SessionsDTO getSessionsBySessionId(User user, Integer limit, Integer offs
return sessions;

} catch (SessionManagementException e) {
log.error(e.getMessage());
handleSessionManagementException(e);
return null;
throw handleSessionManagementException(e);
}
}

Expand Down Expand Up @@ -108,7 +106,7 @@ public void terminateSessionsByUserId(User user) {
String userId = resolveUserIdFromUser(user);
SessionManagementUtil.getUserSessionManagementService().terminateSessionsByUserId(userId);
} catch (SessionManagementException e) {
handleSessionManagementException(e);
throw handleSessionManagementException(e);
}
}

Expand All @@ -117,7 +115,7 @@ private List<SessionDTO> buildSessionDTOs(List<UserSession> userSessionList) {
return userSessionList.stream().map(new UserSessionToExternal()).collect(Collectors.toList());
}

private void handleSessionManagementException(SessionManagementException e) {
private APIError handleSessionManagementException(SessionManagementException e) {

ErrorResponse errorResponse = getErrorBuilder(e).build(log, e, e.getDescription());

Expand All @@ -137,7 +135,7 @@ private void handleSessionManagementException(SessionManagementException e) {
status = Response.Status.INTERNAL_SERVER_ERROR;
}

throw new APIError(status, errorResponse);
return new APIError(status, errorResponse);
}

private ErrorResponse.Builder getErrorBuilder(SessionManagementException error) {
Expand Down

0 comments on commit 6c814e7

Please sign in to comment.