提前检查输入JSON格式

pull/53/head
kurami 2 years ago
parent 957b5678d9
commit 2e04fa4dca

@ -2,7 +2,9 @@ package com.java3y.austin.web.controller;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.java3y.austin.common.constant.AustinConstant;
import com.java3y.austin.common.enums.AccountFormat;
import com.java3y.austin.common.enums.RespStatusEnum;
import com.java3y.austin.support.domain.ChannelAccount;
import com.java3y.austin.web.annotation.AustinAspect;
@ -48,6 +50,7 @@ public class ChannelAccountController {
@PostMapping("/save")
@ApiOperation("/保存数据")
public ChannelAccount saveOrUpdate(@RequestBody ChannelAccount channelAccount) {
accountConfigPreCheck(channelAccount);
if (loginUtils.needLogin() && StrUtil.isBlank(channelAccount.getCreator())) {
throw new CommonException(RespStatusEnum.NO_LOGIN.getCode(), RespStatusEnum.NO_LOGIN.getMsg());
}
@ -99,4 +102,14 @@ public class ChannelAccountController {
}
}
/**
* JSON
*/
public void accountConfigPreCheck(ChannelAccount channelAccount) throws CommonException{
try{
JSON.parseObject(channelAccount.getAccountConfig(), Object.class);
}catch (Exception e){
throw new CommonException(RespStatusEnum.CLIENT_BAD_PARAMETERS.getCode(), RespStatusEnum.CLIENT_BAD_PARAMETERS.getMsg());
}
}
}

Loading…
Cancel
Save