-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
선택지 통계 조회 기능 구현 #83
선택지 통계 조회 기능 구현 #83
Changes from 1 commit
428293a
5eb92f2
14bbcb1
59444e1
e15c148
d5fb3e4
9e7ab3a
3a0adfd
3a81d84
8b66134
67dd311
9b54935
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.votogether.exception; | ||
|
||
public class BadRequestException extends BaseException { | ||
|
||
public BadRequestException(final ExceptionType exceptionType) { | ||
super(exceptionType); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.votogether.exception; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class BaseException extends RuntimeException { | ||
|
||
private final ExceptionType exceptionType; | ||
|
||
public BaseException(final ExceptionType exceptionType) { | ||
this.exceptionType = exceptionType; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.votogether.exception; | ||
|
||
public record ExceptionResponse(int code, String message) { | ||
|
||
public static ExceptionResponse from(final BaseException e) { | ||
final ExceptionType exceptionType = e.getExceptionType(); | ||
return new ExceptionResponse(exceptionType.getCode(), exceptionType.getMessage()); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.votogether.exception; | ||
|
||
public interface ExceptionType { | ||
|
||
int getCode(); | ||
|
||
String getMessage(); | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.votogether.exception; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
@RestControllerAdvice | ||
public class GlobalExceptionHandler { | ||
|
||
@ExceptionHandler | ||
public ResponseEntity<ExceptionResponse> handleException(final Exception e) { | ||
return ResponseEntity.internalServerError() | ||
.body(new ExceptionResponse(-9999, "알 수 없는 서버 에러가 발생했습니다.")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Q : 전 알 수 없는 에러의 경우 500 을 보내주었었는데, -9999로 하신 이유가 있나요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. HTTP 상태코드는 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이건 제가 잘못 파악했었네요--ㅋ |
||
} | ||
|
||
@ExceptionHandler | ||
public ResponseEntity<ExceptionResponse> handleBadRequestException(final BadRequestException e) { | ||
return ResponseEntity.badRequest() | ||
.body(ExceptionResponse.from(e)); | ||
} | ||
|
||
@ExceptionHandler | ||
public ResponseEntity<ExceptionResponse> handleNotFoundException(final NotFoundException e) { | ||
return ResponseEntity.status(HttpStatus.NOT_FOUND) | ||
.body(ExceptionResponse.from(e)); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.votogether.exception; | ||
|
||
public class NotFoundException extends BaseException { | ||
|
||
public NotFoundException(final ExceptionType exceptionType) { | ||
super(exceptionType); | ||
} | ||
Comment on lines
+3
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q
: 에러코드는 주로 어쩔때 사용하고 에러코드를 지정하는 기준은 무엇인가요??There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
추후에 에러를 로그로 남기게 되었을 때, 여러 로그 중 에러 메시지로 에러를 찾기보다는 특정 에러 코드값으로 에러를 찾는 것이 더 용이하다고 판단되어 에러 코드도 추가해 보았습니다!
에러 코드를 지정하는 기준은 아직 정하지 않아서 다 같이 얘기해보면 좋을 것 같아요 :)