Skip to content

Commit

Permalink
feat(Stadium, Rgb) : custom exception 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
EunjiShin committed Jul 12, 2024
1 parent 04d059d commit 1131fb8
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.depromeet.spot.common.exception.stadium;

import org.depromeet.spot.common.exception.ErrorCode;
import org.springframework.http.HttpStatus;

import lombok.Getter;

@Getter
public enum StadiumErrorCode implements ErrorCode {
STADIUM_NOT_FOUND(HttpStatus.NOT_FOUND, "ST001", "요청 경기장이 존재하지 않습니다."),
;

private final HttpStatus status;
private final String code;
private String message;

StadiumErrorCode(HttpStatus status, String code, String message) {
this.status = status;
this.code = code;
this.message = message;
}

public StadiumErrorCode appended(Object o) {
message = message + " {" + o.toString() + "}";
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.depromeet.spot.common.exception.stadium;

import org.depromeet.spot.common.exception.BusinessException;

public abstract class StadiumException extends BusinessException {

protected StadiumException(StadiumErrorCode errorCode) {
super(errorCode);
}

public static class StadiumNotFoundException extends StadiumException {
public StadiumNotFoundException() {
super(StadiumErrorCode.STADIUM_NOT_FOUND);
}

public StadiumNotFoundException(String str) {
super(StadiumErrorCode.STADIUM_NOT_FOUND.appended(str));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.depromeet.spot.common.exception.util;

import org.depromeet.spot.common.exception.ErrorCode;
import org.springframework.http.HttpStatus;

import lombok.Getter;

@Getter
public enum UtilErrorCode implements ErrorCode {
INVALID_RGB_CODE(HttpStatus.BAD_REQUEST, "UT001", "잘못된 RGB 코드 값 입니다."),
;

private final HttpStatus status;
private final String code;
private String message;

UtilErrorCode(HttpStatus status, String code, String message) {
this.status = status;
this.code = code;
this.message = message;
}

public UtilErrorCode appended(Object o) {
message = message + " {" + o.toString() + "}";
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.depromeet.spot.common.exception.util;

import org.depromeet.spot.common.exception.BusinessException;

public abstract class UtilException extends BusinessException {
protected UtilException(UtilErrorCode errorCode) {
super(errorCode);
}

public static class InvalidRgbCodeException extends UtilException {
public InvalidRgbCodeException() {
super(UtilErrorCode.INVALID_RGB_CODE);
}
}
}
1 change: 1 addition & 0 deletions domain/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
dependencies {
implementation(project(":common"))
}

tasks.jar { enabled = true }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.depromeet.spot.domain.common;

import org.depromeet.spot.common.exception.util.UtilException.InvalidRgbCodeException;

import lombok.Builder;
import lombok.Getter;

Expand All @@ -20,8 +22,7 @@ public RgbCode(Integer red, Integer green, Integer blue) {

private static void isValidRgb(Integer red, Integer green, Integer blue) {
if (red == null || green == null || blue == null) {
// FIXME: custom exception 대체
throw new IllegalArgumentException();
throw new InvalidRgbCodeException();
}
}
}
1 change: 1 addition & 0 deletions infrastructure/jpa/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
dependencies {
implementation(project(":common"))
implementation(project(":domain"))
implementation(project(":usecase"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;

import org.depromeet.spot.common.exception.stadium.StadiumException.StadiumNotFoundException;
import org.depromeet.spot.domain.stadium.Stadium;
import org.depromeet.spot.jpa.stadium.entity.StadiumEntity;
import org.depromeet.spot.usecase.port.out.stadium.StadiumRepository;
Expand All @@ -17,10 +18,10 @@ public class StadiumRepositoryImpl implements StadiumRepository {

@Override
public Stadium findById(final Long id) {
// FIXME: custom exception 추가
StadiumEntity entity =
stadiumJpaRepository.findById(id).orElseThrow(IllegalArgumentException::new);
return entity.toDomain();
return stadiumJpaRepository
.findById(id)
.orElseThrow(() -> new StadiumNotFoundException(id + "의 경기장은 존재하지 않습니다."))
.toDomain();
}

@Override
Expand Down

0 comments on commit 1131fb8

Please sign in to comment.