Skip to content

Commit dca722b

Browse files
committed
merge: 合并代码,解决代码冲突
1 parent 59b71f8 commit dca722b

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

src/main/java/io/github/talelin/latticy/common/exception/RestExceptionHandler.java

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import java.util.HashMap;
3131
import java.util.List;
3232
import java.util.Map;
33+
import java.util.regex.Matcher;
34+
import java.util.regex.Pattern;
3335

3436
import static io.github.talelin.autoconfigure.util.RequestUtil.getSimpleRequest;
3537

@@ -196,10 +198,16 @@ public UnifyResponseVO processException(HttpMessageNotReadableException exceptio
196198
UnifyResponseVO result = new UnifyResponseVO();
197199
result.setRequest(getSimpleRequest(request));
198200
String errorMessage = CodeMessageConfiguration.getMessage(10170);
199-
if (!StringUtils.hasText(errorMessage)) {
200-
result.setMessage(exception.getMessage());
201+
Throwable cause = exception.getCause();
202+
if(cause != null) {
203+
String msg = this.convertMessage(cause);
204+
result.setMessage(msg);
201205
} else {
202-
result.setMessage(errorMessage);
206+
if (!StringUtils.hasText(errorMessage)) {
207+
result.setMessage(exception.getMessage());
208+
} else {
209+
result.setMessage(errorMessage);
210+
}
203211
}
204212
result.setCode(Code.PARAMETER_ERROR.getCode());
205213
response.setStatus(HttpStatus.BAD_REQUEST.value());
@@ -252,4 +260,26 @@ public UnifyResponseVO processException(Exception exception, HttpServletRequest
252260
response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
253261
return result;
254262
}
263+
264+
/**
265+
* 传参类型错误时,用于消息转换
266+
* @param throwable
267+
* @return 错误信息
268+
*/
269+
private String convertMessage(Throwable throwable) {
270+
String error = throwable.toString();
271+
String regulation = "\\[\"(.*?)\"]+";
272+
Pattern pattern = Pattern.compile(regulation);
273+
Matcher matcher = pattern.matcher(error);
274+
String group = "";
275+
if(matcher.find()) {
276+
String matchString = matcher.group();
277+
matchString = matchString
278+
.replace("[","")
279+
.replace("]","");
280+
matchString = matchString.replaceAll("\\\"","") + "字段类型错误";
281+
group += matchString;
282+
}
283+
return group;
284+
}
255285
}

src/main/java/io/github/talelin/latticy/service/impl/AdminServiceImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ public boolean deleteGroup(Integer id) {
162162
throw new ForbiddenException(10075);
163163
}
164164
throwGroupNotExistById(id);
165+
List<Integer> groupUserIds = groupService.getGroupUserIds(id);
166+
if(groupUserIds.size() > 0) {
167+
throw new ForbiddenException(10027);
168+
}
165169
return groupService.removeById(id);
166170
}
167171

src/main/resources/code-message.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ code-message[10023]=\u5206\u7EC4\u4E0D\u5B58\u5728\uFF0C\u65E0\u6CD5\u65B0\u5EFA
3030
code-message[10024]=\u5206\u7EC4\u4E0D\u5B58\u5728
3131
code-message[10025]=\u627E\u4E0D\u5230\u76F8\u5E94\u7684\u89C6\u56FE\u5904\u7406\u5668
3232
code-message[10026]=\u672A\u627E\u5230\u6587\u4EF6
33+
code-message[10027]=\u5206\u7EC4\u4E0B\u5B58\u5728\u7528\u6237\uFF0C\u4E0D\u53EF\u5220\u9664\u5F53\u524D\u5206\u7EC4
3334
code-message[10030]=\u53C2\u6570\u9519\u8BEF
3435
code-message[10031]=\u7528\u6237\u540D\u6216\u5BC6\u7801\u9519\u8BEF
3536
code-message[10032]=\u8BF7\u8F93\u5165\u6B63\u786E\u7684\u5BC6\u7801

0 commit comments

Comments
 (0)