
+++ src/main/java/com/takensoft/common/exception/CustomPrhibtWordException.java
... | ... | @@ -0,0 +1,33 @@ |
1 | +package com.takensoft.common.exception; | |
2 | + | |
3 | +/** | |
4 | + * @author 하석형 | |
5 | + * @since 2025.03.21 | |
6 | + * @modification | |
7 | + * since | author | description | |
8 | + * 2025.03.21 | 하석형 | 최초 등록 | |
9 | + * | |
10 | + * RuntimeException - 실행 중 발생하는 예외를 처리하는 기본 클래스 | |
11 | + * | |
12 | + * 금칙어 포함 시 발생하는 예외 | |
13 | + */ | |
14 | +public class CustomPrhibtWordException extends RuntimeException { | |
15 | + | |
16 | + private String word; // 금지어 | |
17 | + | |
18 | + public CustomPrhibtWordException() { | |
19 | + } | |
20 | + | |
21 | + public CustomPrhibtWordException(String message, String word) { | |
22 | + super(message); | |
23 | + this.word = word; | |
24 | + } | |
25 | + | |
26 | + public CustomPrhibtWordException(String message, Throwable cause) { | |
27 | + super(message, cause); | |
28 | + } | |
29 | + | |
30 | + public String getWord() { | |
31 | + return word; | |
32 | + } | |
33 | +}(파일 끝에 줄바꿈 문자 없음) |
--- src/main/java/com/takensoft/common/exception/GlobalExceptionHandler.java
+++ src/main/java/com/takensoft/common/exception/GlobalExceptionHandler.java
... | ... | @@ -23,7 +23,7 @@ |
23 | 23 |
* since | author | description |
24 | 24 |
* 2025.01.22 | takensoft | 최초 등록 |
25 | 25 |
* 2025.03.12 | 하석형 | handleCustomCodeDuplicationException, handleCustomDataDuplicationException 추가 |
26 |
- * 2025.03.20 | 하석형 | handleFileSizeLimitExceededException, CustomFileUploadFailException 추가 |
|
26 |
+ * 2025.03.21 | 하석형 | handleFileSizeLimitExceededException, handleCustomFileUploadFailException, handleCustomPrhibtWordException 추가 |
|
27 | 27 |
* |
28 | 28 |
* 스프링 MVC 컨트롤러에서 발생하는 예외를 처리하는 공통 클래스 |
29 | 29 |
*/ |
... | ... | @@ -295,6 +295,18 @@ |
295 | 295 |
} |
296 | 296 |
|
297 | 297 |
/** |
298 |
+ * @param cpwe - CustomPrhibtWordException 예외 객체 |
|
299 |
+ * @return CustomPrhibtWordException 대한 HTTP 응답 |
|
300 |
+ * |
|
301 |
+ * CustomPrhibtWordException 발생한 경우 |
|
302 |
+ */ |
|
303 |
+ @ExceptionHandler(CustomPrhibtWordException.class) |
|
304 |
+ public ResponseEntity<?> handleCustomPrhibtWordException(CustomPrhibtWordException cpwe) { |
|
305 |
+ logError(cpwe); |
|
306 |
+ return resUtil.errorRes(MessageCode.COMMON_PROHIBITION_WORD, "\n* " + cpwe.getWord()); |
|
307 |
+ } |
|
308 |
+ |
|
309 |
+ /** |
|
298 | 310 |
* @param e - Exception 예외 객체 |
299 | 311 |
* @return 기타 예외에 대한 HTTP 응답 |
300 | 312 |
* |
--- src/main/java/com/takensoft/common/message/MessageCode.java
+++ src/main/java/com/takensoft/common/message/MessageCode.java
... | ... | @@ -10,6 +10,7 @@ |
10 | 10 |
* @modification |
11 | 11 |
* since | author | description |
12 | 12 |
* 2025.01.22 | takensoft | 최초 등록 |
13 |
+ * 2025.03.21 | 하석형 | FILE_UPLOAD_FAIL, COMMON_PROHIBITION_WORD 추가 |
|
13 | 14 |
* |
14 | 15 |
* 시스템에서 발생할 수 있는 코드 메시지들을 정의 |
15 | 16 |
*/ |
... | ... | @@ -30,6 +31,7 @@ |
30 | 31 |
COMMON_PAYLOAD_TOO_LARGE("common.payload_too_large",HttpStatus.PAYLOAD_TOO_LARGE), //파일 용량 초과 시 |
31 | 32 |
COMMON_DUPLICATION_CODE("common.duplication_code",HttpStatus.INTERNAL_SERVER_ERROR), //중복 코드 |
32 | 33 |
COMMON_DUPLICATION_DATA("common.duplication_data",HttpStatus.INTERNAL_SERVER_ERROR), //중복 데이터 |
34 |
+ COMMON_PROHIBITION_WORD("common.prohibition_word",HttpStatus.INTERNAL_SERVER_ERROR), //금지어 사용 시 |
|
33 | 35 |
|
34 | 36 |
//네트워크 관련 |
35 | 37 |
NETWORK_UNKNOWN_HOST("network.unknown_host", HttpStatus.BAD_REQUEST), // 알 수 없는 호스트 |
--- src/main/java/com/takensoft/common/util/ResponseUtil.java
+++ src/main/java/com/takensoft/common/util/ResponseUtil.java
... | ... | @@ -19,6 +19,7 @@ |
19 | 19 |
* @modification |
20 | 20 |
* since | author | description |
21 | 21 |
* 2025.01.22 | takensoft | 최초 등록 |
22 |
+ * 2025.03.21 | 하석형 | 에러 응답 추가 메세지 추가 |
|
22 | 23 |
* |
23 | 24 |
* HTTP 응답 처리를 위한 유틸리티 |
24 | 25 |
*/ |
... | ... | @@ -87,10 +88,21 @@ |
87 | 88 |
* 에러 응답 생성 |
88 | 89 |
*/ |
89 | 90 |
public ResponseEntity<?> errorRes(MessageCode messageCode) { |
91 |
+ return errorRes(messageCode, ""); |
|
92 |
+ } |
|
93 |
+ |
|
94 |
+ /** |
|
95 |
+ * @param messageCode - 응답 메시지 코드 |
|
96 |
+ * @param addMessage - 추가 메시지 |
|
97 |
+ * @return 에러 응답 결과 |
|
98 |
+ * |
|
99 |
+ * 에러 응답 생성 |
|
100 |
+ */ |
|
101 |
+ public ResponseEntity<?> errorRes(MessageCode messageCode, String addMessage) { |
|
90 | 102 |
ResponseData responseData = new ResponseData(); |
91 | 103 |
responseData.setStatus(messageCode.getStatus().value()); |
92 | 104 |
responseData.setStatusText(messageCode.getStatus()); |
93 |
- responseData.setMessage(getMessage(messageCode)); |
|
105 |
+ responseData.setMessage(getMessage(messageCode) + (addMessage != null ? addMessage : "")); |
|
94 | 106 |
return new ResponseEntity<>(responseData, createHeaders(), messageCode.getStatus()); |
95 | 107 |
} |
96 | 108 |
} |
--- src/main/resources/message/messages_en.yml
+++ src/main/resources/message/messages_en.yml
... | ... | @@ -13,6 +13,7 @@ |
13 | 13 |
payload_too_large : "File size limit exceeded." |
14 | 14 |
duplication_code: "This code already exists." |
15 | 15 |
duplication_data: "This data already exists." |
16 |
+ prohibition_word: "Contains prohibited words." |
|
16 | 17 |
|
17 | 18 |
|
18 | 19 |
# 네트워크 관련 |
--- src/main/resources/message/messages_ko.yml
+++ src/main/resources/message/messages_ko.yml
... | ... | @@ -13,6 +13,7 @@ |
13 | 13 |
payload_too_large: "파일 용량 제한을 초과했습니다." |
14 | 14 |
duplication_code: "이미 존재하는 코드입니다." |
15 | 15 |
duplication_data: "이미 존재하는 정보입니다." |
16 |
+ prohibition_word: "금지어가 포함되어 있습니다." |
|
16 | 17 |
|
17 | 18 |
# 네트워크 관련 |
18 | 19 |
network: |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?