Skip to content

Commit 972fe02

Browse files
committed
feat(basis): 新增错误码
1 parent 4b8cba6 commit 972fe02

File tree

9 files changed

+27
-0
lines changed

9 files changed

+27
-0
lines changed

mumu-basis/src/main/java/baby/mumu/basis/response/ResponseCode.java

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public enum ResponseCode implements BaseResponse {
4747
DATA_ALREADY_EXISTS("1003", 400),
4848
DATA_DOES_NOT_EXIST("1004", 400),
4949
PRIMARY_KEY_CANNOT_BE_EMPTY("1005", 400),
50+
REQUEST_MISSING_NECESSARY_PARAMETERS("1006", 400),
5051
/*认证错误2001-2999*/
5152
ACCOUNT_ALREADY_EXISTS("2001", 500),
5253
ACCOUNT_NAME_CANNOT_BE_EMPTY("2002", 500),

mumu-basis/src/main/resources/messages.properties

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
1003=data already exists
1515
1004=data does not exist
1616
1005=primary key cannot be empty
17+
1006=Request missing necessary parameters
1718
2001=account already exists
1819
2002=account name cannot be empty
1920
2003=account password cannot be empty

mumu-basis/src/main/resources/messages_en.properties

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
1003=data already exists
1515
1004=data does not exist
1616
1005=primary key cannot be empty
17+
1006=Request missing necessary parameters
1718
2001=account already exists
1819
2002=account name cannot be empty
1920
2003=account password cannot be empty

mumu-basis/src/main/resources/messages_ja.properties

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
1003=データが既に存在しています
1515
1004=データが存在しません
1616
1005=主キーは空にできません
17+
1006=リクエストに必要なパラメータが不足しています
1718
2001=アカウントが既に存在します
1819
2002=アカウント名は空にできません
1920
2003=アカウントパスワードは空にできません

mumu-basis/src/main/resources/messages_ko.properties

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
1003=데이터가 이미 존재함
1515
1004=데이터가 존재하지 않음
1616
1005=주 키는 비어 있을 수 없음
17+
1006=요청에 필요한 매개변수가 누락되었습니다
1718
2001=계정이 이미 존재함
1819
2002=계정 이름은 비어 있을 수 없음
1920
2003=계정 비밀번호는 비어 있을 수 없음

mumu-basis/src/main/resources/messages_ru.properties

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
1003=Данные уже существуют
1515
1004=Данные не найдены
1616
1005=Первичный ключ не может быть пустым
17+
1006=В запросе отсутствуют необходимые параметры
1718
2001=Аккаунт уже существует
1819
2002=Имя аккаунта не может быть пустым
1920
2003=Пароль аккаунта не может быть пустым

mumu-basis/src/main/resources/messages_zh.properties

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
1003=数据已存在
1515
1004=数据不存在
1616
1005=主键不能为空
17+
1006=请求缺少必要的参数
1718
2001=账户已存在
1819
2002=账户名不能为空
1920
2003=账户密码不能为空

mumu-basis/src/main/resources/messages_zh_TW.properties

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
1003=數據已存在
1515
1004=數據不存在
1616
1005=主鍵不能為空
17+
1006=請求缺少必要的參數
1718
2001=帳戶已存在
1819
2002=帳戶名不能為空
1920
2003=帳戶密碼不能為空

mumu-extension/src/main/java/baby/mumu/extension/processor/response/ResponseBodyProcessor.java

+19
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.springframework.http.server.ServerHttpRequest;
4646
import org.springframework.http.server.ServerHttpResponse;
4747
import org.springframework.web.bind.MethodArgumentNotValidException;
48+
import org.springframework.web.bind.MissingServletRequestParameterException;
4849
import org.springframework.web.bind.annotation.ExceptionHandler;
4950
import org.springframework.web.bind.annotation.RestController;
5051
import org.springframework.web.bind.annotation.RestControllerAdvice;
@@ -186,6 +187,24 @@ public ResponseWrapper<?> handleException(
186187
);
187188
}
188189

190+
@ExceptionHandler(MissingServletRequestParameterException.class)
191+
public ResponseWrapper<?> handleException(
192+
@NotNull MissingServletRequestParameterException missingServletRequestParameterException,
193+
@NotNull HttpServletResponse response) {
194+
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
195+
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
196+
response.setStatus(ResponseCode.REQUEST_MISSING_NECESSARY_PARAMETERS.getStatus());
197+
logger.error(missingServletRequestParameterException.getMessage(),
198+
missingServletRequestParameterException);
199+
systemLogGrpcService.syncSubmit(SystemLogSubmitGrpcCmd.newBuilder()
200+
.setContent(missingServletRequestParameterException.getMessage())
201+
.setCategory("missingServletRequestParameterException")
202+
.setFail(ExceptionUtils.getStackTrace(missingServletRequestParameterException))
203+
.build());
204+
return ResponseWrapper.failure(ResponseCode.REQUEST_MISSING_NECESSARY_PARAMETERS,
205+
missingServletRequestParameterException.getParameterName());
206+
}
207+
189208
@ExceptionHandler(Exception.class)
190209
public ResponseWrapper<?> handleException(@NotNull Exception exception,
191210
@NotNull HttpServletResponse response) {

0 commit comments

Comments
 (0)