From 36aba626b4f40f8aeb15a889c7f6158832ba16df Mon Sep 17 00:00:00 2001 From: Khanh Nguyen Date: Tue, 9 Jul 2024 18:27:19 +0700 Subject: [PATCH] Add warn log --- .../market/assembler/FeedbackModelAssembler.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/marketplace-service/src/main/java/com/axonivy/market/assembler/FeedbackModelAssembler.java b/marketplace-service/src/main/java/com/axonivy/market/assembler/FeedbackModelAssembler.java index aa7e71af9..a981b099a 100644 --- a/marketplace-service/src/main/java/com/axonivy/market/assembler/FeedbackModelAssembler.java +++ b/marketplace-service/src/main/java/com/axonivy/market/assembler/FeedbackModelAssembler.java @@ -3,8 +3,10 @@ import com.axonivy.market.controller.FeedbackController; import com.axonivy.market.entity.Feedback; import com.axonivy.market.entity.User; +import com.axonivy.market.exceptions.model.NotFoundException; import com.axonivy.market.model.FeedbackModel; import com.axonivy.market.service.UserService; +import lombok.extern.log4j.Log4j2; import org.apache.commons.lang3.StringUtils; import org.springframework.hateoas.server.mvc.RepresentationModelAssemblerSupport; import org.springframework.stereotype.Component; @@ -12,6 +14,7 @@ import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo; import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn; +@Log4j2 @Component public class FeedbackModelAssembler extends RepresentationModelAssemblerSupport { @@ -31,7 +34,14 @@ public FeedbackModel toModel(Feedback feedback) { } private FeedbackModel createResource(FeedbackModel model, Feedback feedback) { - User user = userService.findUser(feedback.getUserId()); + User user; + try { + user = userService.findUser(feedback.getUserId()); + } + catch (NotFoundException e) { + log.warn(e.getMessage()); + user = new User(); + } model.setId(feedback.getId()); model.setUsername(StringUtils.isBlank(user.getName()) ? user.getUsername() : user.getName()); model.setUserAvatarUrl(user.getAvatarUrl());