Skip to content

Commit

Permalink
Merge pull request #8 from kakao-tech-campus-2nd-step3/develop
Browse files Browse the repository at this point in the history
* ExceptionAdvice 정의 (#4)

* build: lombok 추가
#3

* chore: build.gradle 정리
#3

* chore: ApplicationError 정의
#3

* chore: BusinessError 정의
#3

* feat: ExceptionAdvice 정의
- BusinessError
- ApplicationError
#3

* chore: exception -> error 패키지명 수정
#3

* chore: error logging 방식 수정
- [] : {}
#3

* DOCS : PR template 업데이트

---------

Co-authored-by: 정지민 <[email protected]>
Co-authored-by: amm0124 <[email protected]>
  • Loading branch information
3 people authored Sep 20, 2024
2 parents e5c56ce + 608e76b commit e8f61ec
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 23 deletions.
24 changes: 8 additions & 16 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
## TO-DO
## 해결하려는 문제가 무엇인가요?

어떤 것을 하셨나요?
어떤 것 작업했는지 작성해주세요! 아래는 예시입니다.
자세하면 자세할수록 좋습니다!
- close #

- [ ] build.gradle 의존성 추가
- [ ] login controller 구현
- [ ] 파이팅 ~
## 어떻게 해결했나요?

## 추가 정보
-

하고 싶은 말이 있으면 작성해주세요!
## 코드 리뷰시 요청 사항

## 리뷰어
-

꼭 봐줬으면 하는 사람이 있으면 @<< 를 통해서 태그!


## 관련 이슈 닫기

closes (#이슈 번호)
## 더 하고 싶은 말

-
30 changes: 23 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,38 @@ repositories {
}

dependencies {
// Spring Boot Basic
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
runtimeOnly 'com.h2database:h2'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5'

// Spring Security
implementation 'org.springframework.security:spring-security-crypto:5.7.1'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'

// H2 Database
runtimeOnly 'com.h2database:h2'

// JSON
implementation 'org.json:json:20210307'
implementation 'com.google.code.gson:gson:2.10.1'

// JWT
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5'

// Lombok
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'

// Test
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}


tasks.named('test') {
useJUnitPlatform()
}
13 changes: 13 additions & 0 deletions src/main/java/poomasi/global/error/ApplicationError.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package poomasi.global.error;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum ApplicationError {
EXAMPLE_ERROR("애플리케이션 에러 예시입니다.");

private final String message;

}
10 changes: 10 additions & 0 deletions src/main/java/poomasi/global/error/ApplicationException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package poomasi.global.error;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class ApplicationException extends RuntimeException {
private final ApplicationError applicationError;
}
16 changes: 16 additions & 0 deletions src/main/java/poomasi/global/error/BusinessError.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package poomasi.global.error;

import org.springframework.http.HttpStatus;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum BusinessError {
EXAMPLE_ERROR(HttpStatus.BAD_REQUEST, "에러 예시입니다.");

private final HttpStatus httpStatus;

private final String message;
}
10 changes: 10 additions & 0 deletions src/main/java/poomasi/global/error/BusinessException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package poomasi.global.error;

import lombok.AllArgsConstructor;
import lombok.Getter;

@AllArgsConstructor
@Getter
public class BusinessException extends RuntimeException {
private final BusinessError businessError;
}
34 changes: 34 additions & 0 deletions src/main/java/poomasi/global/error/ExceptionAdvice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package poomasi.global.error;

import org.springframework.http.HttpStatus;
import org.springframework.web.ErrorResponse;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestControllerAdvice
public class ExceptionAdvice {

@ExceptionHandler(BusinessException.class)
public ErrorResponse businessExceptionHandler(BusinessException exception) {
BusinessError businessError = exception.getBusinessError();
log.warn("[{}] : {}", businessError.name(), businessError.getMessage());
return ErrorResponse
.builder(exception, businessError.getHttpStatus(), businessError.getMessage())
.title(businessError.name())
.build();
}

@ExceptionHandler(ApplicationException.class)
public ErrorResponse applicationExceptionHandler(ApplicationException exception) {
ApplicationError applicationError = exception.getApplicationError();
log.error("[{}] : {}", applicationError.name(), applicationError.getMessage(),
exception);
return ErrorResponse
.builder(exception, HttpStatus.INTERNAL_SERVER_ERROR, applicationError.getMessage())
.title(exception.getClass().getSimpleName())
.build();
}
}

0 comments on commit e8f61ec

Please sign in to comment.