Skip to content

Commit

Permalink
[feat] logic for creat fail response
Browse files Browse the repository at this point in the history
  • Loading branch information
kgy1008 committed Jul 16, 2024
1 parent 6672d55 commit 1e59bab
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion server-yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.hankki.hankkiserver.common.exception.ConflictException;
import org.hankki.hankkiserver.common.exception.NotFoundException;
import org.hankki.hankkiserver.common.exception.UnauthorizedException;

import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
Expand Down Expand Up @@ -35,9 +34,9 @@ public HankkiResponse<Void> handleEntityNotFoundException(NotFoundException e) {
}

@ExceptionHandler(ConflictException.class)
public HankkiResponse<Void> handleConflictException(ConflictException e) {
public HankkiResponse<Object> handleConflictException(ConflictException e) {
log.error("handleConflictException() in GlobalExceptionHandler throw ConflictException : {}", e.getMessage());
return HankkiResponse.fail(e.getErrorCode());
return HankkiResponse.fail(e.getErrorCode(), e.getData());
}

@ExceptionHandler(MissingServletRequestParameterException.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ public static <T> HankkiResponse<T> success(SuccessCode success, T data) {
public static <T> HankkiResponse<T> fail(ErrorCode error) {
return new HankkiResponse<>(error.getHttpStatus().value(), error.getMessage());
}

public static <T> HankkiResponse<T> fail(ErrorCode error, T data) {
return new HankkiResponse<>(error.getHttpStatus().value(), error.getMessage(), data);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void validateDuplicatedStore(final StoreValidationCommand command) {
private void findUniversityStore(final Long universityId, final Store store) {
universityStoreFinder.findByUniversityIdAndStore(universityId, store)
.ifPresent(universityStore -> {
throw new ConflictException(StoreErrorCode.STORE_ALREADY_REGISTERED);
throw new ConflictException(StoreErrorCode.STORE_ALREADY_REGISTERED, new StoreDuplicateValidationResponse(store.getId()));
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@
@Getter
public class ConflictException extends RuntimeException {
private final ErrorCode errorCode;
private Object data;

public ConflictException(ErrorCode errorCode) {
super(errorCode.getMessage());
this.errorCode = errorCode;
}

public ConflictException(ErrorCode errorCode, Object data) {
super(errorCode.getMessage());
this.errorCode = errorCode;
this.data = data;
}
}

0 comments on commit 1e59bab

Please sign in to comment.