Commit 0c950623 authored by gongzuquan's avatar gongzuquan

异常信息优化

parent aff8222f
......@@ -13,56 +13,90 @@ public class YzgError {
private static YzgErrorData error = new YzgErrorData("999.");
private static void init() {
error.add("000","%s");
error.add("000", "%s");
error.add("001", "该页面未绑定表");
error.add("002", "类%s未发现表结构");
error.add("003", "类%s未发现SQL语句%s");
error.add("004", "泛型继承检测错误");
error.add("005","视频文件不存在");
error.add("006","对象%s不能复制");
error.add("007","整形转换成字节的PCD码必须小于100");
error.add("008","不能识别文件类型%s");
error.add("009","文件类型不为图片、音频、视频");
error.add("010","文件%s已存在文件,不能创建目录");
error.add("011","创建文件夹失败");
error.add("012","文件删除失败");
error.add("013","变量名%s不支持");
error.add("014","正则表达式错误");
error.add("015","length params is error, must be greater than 0, this params is [%s]");
error.add("016","random code, essential data is empty.");
error.add("017","生成时间搓 MD5 ID 时,时间不能为空");
error.add("018","压缩时文件夹对象不能为空。");
error.add("019","[%s]不是一个文件夹,或者不存在。");
error.add("020","删除文件失败");
error.add("021","文件%s不存在");
error.add("022","没有抛出异常");
error.add("023","监视错误");
error.add("024","导出时请传入配置信息");
error.add("025","不能处理非本条件的字段");
error.add("026","代码片段%s:%s:%s为单数");
error.add("027","SqlCondItem不支持输入参数,必须带代码片段");
error.add("028","需要格式化的字符串不支持");
error.add("029","表%s主键值为空时不能更新");
error.add("030","修改失败,请确认是否被其他人修改,版本号传入是否正确");
error.add("031","统计类型[%s]不支持");
error.add("032","SQL语句%s不存在纬度%s");
error.add("033","表中未包含MD5字段");
error.add("034","Excel已初始化");
error.add("035","保存失败");
error.add("036","保存路径%s失败");
error.add("037","%s失败,该数据可能已被修改");
error.add("038","size请在0~1之间");
error.add("039","视频转码压缩时文件不存在:%s");
error.add("040","audioBitRateZip请在0~1之间");
error.add("041","videoSizeZip请在0~1之间");
error.add("042","videoBitRateZip请在0~1之间");
error.add("043","你需要格式化的字符串格式为空");
error.add("044","不能获取文件Mime类型%s");
error.add("045","下载失败");
error.add("046","创建对象%s出错");
error.add("047","不能识别模板");
error.add("048","获取视频所缩类图失败:%s");
error.add("005", "视频文件不存在");
error.add("006", "对象%s不能复制");
error.add("007", "整形转换成字节的PCD码必须小于100");
error.add("008", "不能识别文件类型%s");
error.add("009", "文件类型不为图片、音频、视频");
error.add("010", "文件%s已存在文件,不能创建目录");
error.add("011", "创建文件夹失败");
error.add("012", "文件删除失败");
error.add("013", "变量名%s不支持");
error.add("014", "正则表达式错误");
error.add("015", "长度参数为错误,必须大于0,此参数为[%s]");
error.add("016", "随机码,基本数据为空。");
error.add("017", "生成时间搓 MD5 ID 时,时间不能为空");
error.add("018", "压缩时文件夹对象不能为空。");
error.add("019", "[%s]不是一个文件夹,或者不存在。");
error.add("020", "删除文件失败");
error.add("021", "文件%s不存在");
error.add("022", "没有抛出异常");
error.add("023", "监视错误");
error.add("024", "导出时请传入配置信息");
error.add("025", "不能处理非本条件的字段");
error.add("026", "代码片段%s:%s:%s为单数");
error.add("027", "SqlCondItem不支持输入参数,必须带代码片段");
error.add("028", "需要格式化的字符串不支持");
error.add("029", "表%s主键值为空时不能更新");
error.add("030", "修改失败,请确认是否被其他人修改,版本号传入是否正确");
error.add("031", "统计类型[%s]不支持");
error.add("032", "SQL语句%s不存在纬度%s");
error.add("033", "表中未包含MD5字段");
error.add("034", "Excel已初始化");
error.add("035", "保存失败");
error.add("036", "保存路径%s失败");
error.add("037", "%s失败,该数据可能已被修改");
error.add("038", "size请在0~1之间");
error.add("039", "视频转码压缩时文件不存在:%s");
error.add("040", "audioBitRateZip请在0~1之间");
error.add("041", "videoSizeZip请在0~1之间");
error.add("042", "videoBitRateZip请在0~1之间");
error.add("043", "你需要格式化的字符串格式为空");
error.add("044", "不能获取文件Mime类型%s");
error.add("045", "下载失败");
error.add("046", "创建对象%s出错");
error.add("047", "不能识别模板");
error.add("048", "获取视频所缩类图失败:%s");
error.add("049", "没有找到%s的数据");
error.add("050", "地区编码不合法,长度不为9");
error.add("051", "地区编码不合法,长度大于9");
error.add("052", "获取百度接口日期失败");
error.add("053", "获取百度日期正则表达式失败");
error.add("054", "获取百度日期返回错误状态:%s");
error.add("055", "获取百度日期数据格式已修改");
error.add("056", "解密失败:%s");
error.add("057", "请配置yzg.upload.server");
error.add("058", "请配置yzg.upload.display");
error.add("059", "Cookies缺少[%s]");
error.add("060", "名称不能为空");
error.add("061", "请先登录");
error.add("062", "请上传文件");
error.add("063", "文件[%s]保存失败");
error.add("064", "文件[%s]不存在");
error.add("065", "文件[%s]是目录");
error.add("066", "请传入需要移动的文件");
error.add("067", "移动来源路径不能为空");
error.add("068", "移动目标路径不能为空");
error.add("069", "不能用文件 %s 覆盖文件夹 %s");
error.add("070", "移动文件 %s 到 %s 失败,原因:%s");
error.add("071", "来源文件不存在");
error.add("072", "来源文件不为视频");
error.add("073", "获取视频缩略图失败");
error.add("074", "请传入%s文件");
error.add("075", "文件夹不能包含两个.");
error.add("076", "文件夹不能包含\\u");
error.add("077", "队列 %s 不存在");
error.add("078", "交换器 %s 不存在");
error.add("079", "算法错误");
error.add("080", "当前队列没有消息");
error.add("081", "消息队列%s消息%s已经执行");
error.add("082", "请传入queue和messageId");
}
......
package com.yanzuoguang.util.cache;
import com.yanzuoguang.util.YzgError;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.StringHelper;
......@@ -43,7 +44,7 @@ public abstract class MemoryCacheNullUtil<T, M> {
public M getCheck(T key) {
M databaseId = get(key);
if (databaseId == null) {
throw new CodeException("没有找到" + key + "的数据");
throw YzgError.getRuntimeException("049", key);
}
return databaseId;
}
......
package com.yanzuoguang.util.helper;
import com.yanzuoguang.util.YzgError;
import com.yanzuoguang.util.exception.CodeException;
public class AreaHelper {
......@@ -52,7 +53,7 @@ public class AreaHelper {
if (StringHelper.isEmpty(fromAreaId)) {
return fromAreaId;
} else if (fromAreaId.length() != AREA_LENGTH) {
throw new CodeException("地区编码不合法,长度不为9");
throw YzgError.getRuntimeException("050");
}
// 获取国家
String country = fromAreaId.substring(0, 3);
......@@ -94,7 +95,7 @@ public class AreaHelper {
if (StringHelper.isEmpty(fromAreaId)) {
return fromAreaId;
} else if (fromAreaId.length() > AREA_LENGTH) {
throw new CodeException("地区编码不合法,长度大于9");
throw YzgError.getRuntimeException("051");
} else {
StringBuilder sb = new StringBuilder();
sb.append(fromAreaId);
......
package com.yanzuoguang.util.helper;
import com.yanzuoguang.util.YzgError;
import com.yanzuoguang.util.exception.CodeException;
import java.util.Date;
......@@ -145,22 +146,22 @@ public class BaiduHelper {
String post = HttpHelper.get(fullUrl, "gbk");
if (StringHelper.isEmpty(post)) {
throw new CodeException("获取百度接口日期失败");
throw YzgError.getRuntimeException("052");
}
Matcher matcher = REGEX.matcher(post);
if (!matcher.find()) {
throw new CodeException("获取百度日期正则表达式失败");
throw YzgError.getRuntimeException("053");
}
String group = matcher.group(1);
BaiduDate deserialize = JsonHelper.deserialize(group, BaiduDate.class);
if (!StringHelper.compare(deserialize.status, "0")) {
throw new CodeException("获取百度日期返回错误状态:" + deserialize.status, deserialize);
throw YzgError.getRuntimeException("054", deserialize.status, deserialize);
}
if (ArrayHelper.isEmpty(deserialize.getData())) {
throw new CodeException("获取百度日期数据格式已修改", deserialize);
throw YzgError.getRuntimeException("055", deserialize);
}
if (ArrayHelper.isEmpty(deserialize.getData().get(0).almanac)) {
throw new CodeException("获取百度日期数据格式已修改", deserialize);
throw YzgError.getRuntimeException("055", deserialize);
}
return deserialize;
}
......
package com.yanzuoguang.util.helper;
import com.yanzuoguang.util.YzgError;
import com.yanzuoguang.util.contants.SystemContants;
import com.yanzuoguang.util.exception.CodeException;
import org.slf4j.Logger;
......@@ -264,7 +265,7 @@ public final class RsaHelper {
return new String(to, SystemContants.UTF8);
} catch (Exception ex) {
throw new CodeException("解密失败:" + ex.getMessage(), ex);
throw YzgError.getRuntimeException(ex,"056",ex.getMessage());
}
}
......
package com.yanzuoguang.cloud;
import com.yanzuoguang.util.YzgError;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.StringHelper;
import org.springframework.beans.factory.annotation.Value;
......@@ -114,14 +115,14 @@ public class CloudConfig {
public String getServerUrl() {
if (StringHelper.isEmpty(this.serverUrl)) {
throw new CodeException("请配置yzg.upload.server");
throw YzgError.getRuntimeException("057");
}
return serverUrl;
}
public String getDisplayUrl() {
if (StringHelper.isEmpty(this.serverUrl)) {
throw new CodeException("请配置yzg.upload.display");
throw YzgError.getRuntimeException("058");
}
return displayUrl;
}
......
package com.yanzuoguang.cloud.helper;
import com.yanzuoguang.token.TokenHelper;
import com.yanzuoguang.util.YzgError;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.StringHelper;
import org.springframework.web.context.request.RequestContextHolder;
......@@ -85,7 +86,7 @@ public class CookiesHelper {
for (int i = 0; i < keyLength; i++) {
String itemKey = String.format(TAG_FORMAT, key, i);
if (!map.containsKey(itemKey)) {
throw new CodeException("Cookies缺少[" + itemKey + "]");
throw YzgError.getRuntimeException("059", itemKey);
}
sb.append(map.get(itemKey));
}
......
package com.yanzuoguang.dao;
import com.yanzuoguang.util.YzgError;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.StringHelper;
......@@ -340,7 +341,7 @@ public class DaoConst {
*/
public static String getArrayParameterName(String name) {
if (StringHelper.isEmpty(name)) {
throw new CodeException("名称不对");
throw YzgError.getRuntimeException("060");
}
String lName = name.toLowerCase();
if (lName.endsWith(DaoConst.CODE_WHERE_IN_END)) {
......
package com.yanzuoguang.token;
import com.yanzuoguang.util.YzgError;
import com.yanzuoguang.util.base.ObjectHelper;
import com.yanzuoguang.util.cache.MemoryCache;
import com.yanzuoguang.util.exception.CodeException;
......@@ -76,7 +77,7 @@ public class TokenHelper {
TokenData tokenData = cache.get(id);
if (tokenData == null) {
if (checkFlag) {
throw new CodeException("请先登录");
throw YzgError.getRuntimeException("061");
}
return null;
}
......@@ -91,7 +92,7 @@ public class TokenHelper {
}
if (tokenData == null || tokenData.getData() == null) {
if (checkFlag) {
throw new CodeException("请先登录");
throw YzgError.getRuntimeException("061");
}
return null;
}
......
......@@ -5,6 +5,7 @@ import com.yanzuoguang.cloud.helper.HttpFileHelper;
import com.yanzuoguang.cloud.vo.YzgFileUploadReqVo;
import com.yanzuoguang.util.MediaHelper;
import com.yanzuoguang.util.MediaParameter;
import com.yanzuoguang.util.YzgError;
import com.yanzuoguang.util.cache.MemoryCache;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.DateHelper;
......@@ -77,7 +78,7 @@ public class YzgFileServiceImpl implements YzgFileService, ApplicationContextAwa
public YzgFileUploadResVo upload(YzgFileUploadReqVo req) {
YzgFileUploadResVo res = new YzgFileUploadResVo();
if (req.getFile() == null || req.getFile().length == 0) {
throw new CodeException("请上传文件");
throw YzgError.getRuntimeException("062");
}
String folder = checkFolder(req.getFolder());
for (MultipartFile uploadFile : req.getFile()) {
......@@ -101,7 +102,7 @@ public class YzgFileServiceImpl implements YzgFileService, ApplicationContextAwa
try {
uploadFile.transferTo(file);
} catch (Exception ex) {
throw new CodeException("文件保存失败", ex);
throw YzgError.getRuntimeException(ex, "063", file.getName());
}
// 视频上传结果
......@@ -174,10 +175,10 @@ public class YzgFileServiceImpl implements YzgFileService, ApplicationContextAwa
// 父文件夹不存在子文件时则删除
File file = new File(fromFullUrl);
if (!file.exists()) {
throw new CodeException("文件不存在");
throw YzgError.getRuntimeException("064", file.getName());
}
if (file.isDirectory()) {
throw new CodeException("文件是目录");
throw YzgError.getRuntimeException("065", file.getName());
}
HttpFileHelper.localToDown(fromFullUrl, StringHelper.EMPTY, response);
}
......@@ -190,7 +191,7 @@ public class YzgFileServiceImpl implements YzgFileService, ApplicationContextAwa
@Override
public void moveFile(YzgFileMoveReqVo req) {
if (req.getList() == null || req.getList().isEmpty()) {
throw new CodeException("请传入需要移动的文件");
throw YzgError.getRuntimeException("066");
}
// 先检查一遍参数
......@@ -206,10 +207,10 @@ public class YzgFileServiceImpl implements YzgFileService, ApplicationContextAwa
private void checkMove(YzgFileMoveItemReqVo item) {
if (StringHelper.isEmpty(item.getFrom())) {
throw new CodeException("移动来源路径不能为空");
throw YzgError.getRuntimeException("067");
}
if (StringHelper.isEmpty(item.getTo())) {
throw new CodeException("移动目标路径不能为空");
throw YzgError.getRuntimeException("068");
}
checkFolder(item.getFrom());
......@@ -222,7 +223,7 @@ public class YzgFileServiceImpl implements YzgFileService, ApplicationContextAwa
if (fileFrom.exists() && fileTo.exists()) {
if (fileFrom.isFile() && fileTo.isDirectory()) {
throw new CodeException(String.format("不能用文件 %s 覆盖文件夹 %s", item.getFrom(), item.getTo()));
throw YzgError.getRuntimeException("069", item.getFrom(), item.getTo());
}
}
}
......@@ -240,7 +241,7 @@ public class YzgFileServiceImpl implements YzgFileService, ApplicationContextAwa
// 防止另外一个线程移动中
if (fileFrom.exists() && fileTo.exists()) {
if (fileFrom.isFile() && fileTo.isDirectory()) {
throw new CodeException(String.format("不能用文件 %s 覆盖文件夹 %s", item.getFrom(), item.getTo()));
throw YzgError.getRuntimeException("069", item.getFrom(), item.getTo());
}
} else if (!fileFrom.exists()) {
return;
......@@ -253,7 +254,7 @@ public class YzgFileServiceImpl implements YzgFileService, ApplicationContextAwa
try {
Files.move(Paths.get(fullFrom), Paths.get(fullTo), StandardCopyOption.REPLACE_EXISTING);
} catch (Exception ex) {
throw new CodeException(String.format("移动文件 %s 到 %s 失败,原因:%s", item.getFrom(), item.getTo(), ex.getMessage()));
throw YzgError.getRuntimeException("070", item.getFrom(), item.getTo(), ex.getMessage());
}
}
......@@ -329,10 +330,10 @@ public class YzgFileServiceImpl implements YzgFileService, ApplicationContextAwa
String fullFrom = fileConfig.getServerFullPath(req.getFrom());
YzgFileBaseVo fromInfo = fileConfig.init(fullFrom);
if (StringHelper.isEmpty(fromInfo.getMime())) {
throw new CodeException("来源文件不存在");
throw YzgError.getRuntimeException("071");
}
if (fromInfo.getType() != FileHelper.FILE_TYPE_VIDEO) {
throw new CodeException("来源文件不为视频");
throw YzgError.getRuntimeException("072");
}
try {
......@@ -344,7 +345,7 @@ public class YzgFileServiceImpl implements YzgFileService, ApplicationContextAwa
// 获取第一帧做为缩略图
MediaHelper.getVideoFirstImage(fullFrom, fullTo);
} catch (CodeException e) {
throw new CodeException("获取视频缩略图失败", e);
throw YzgError.getRuntimeException(e, "073");
}
}
......@@ -394,7 +395,7 @@ public class YzgFileServiceImpl implements YzgFileService, ApplicationContextAwa
String from = fileConfig.getServerFullPath(req.getFrom());
YzgFileBaseVo fromInfo = fileConfig.init(from);
if (fromInfo.getType() != type) {
throw new CodeException("请传入" + tag + "文件");
throw YzgError.getRuntimeException("074", tag);
}
// 循环转换所有文件
......@@ -464,10 +465,10 @@ public class YzgFileServiceImpl implements YzgFileService, ApplicationContextAwa
private String checkFolder(String folderFrom) {
String folder = StringHelper.getFirst(folderFrom, "temp");
if (folder.contains("..")) {
throw new CodeException("文件夹不能包含两个.");
throw YzgError.getRuntimeException("075");
}
if (folder.contains("\\u")) {
throw new CodeException("文件夹不能包含\\u");
throw YzgError.getRuntimeException("076");
}
return folder;
......
package com.yanzuoguang.mq.dao;
import com.yanzuoguang.dao.DaoConst;
import com.yanzuoguang.util.YzgError;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.StringHelper;
import com.yanzuoguang.util.log.Log;
......@@ -41,7 +42,7 @@ public class BeanDao {
String key = StringHelper.getId(QUEUE, queueName);
Queue ret = getBean(Queue.class, key);
if (ret == null) {
throw new CodeException(String.format("队列 %s 不存在", queueName));
throw YzgError.getRuntimeException("077", queueName);
}
return ret;
}
......@@ -56,7 +57,7 @@ public class BeanDao {
String key = StringHelper.getId(EXCHANGE, exchangeName);
TopicExchange ret = getBean(TopicExchange.class, key);
if (ret == null) {
throw new CodeException(String.format("交换器 %s 不存在", exchangeName));
throw YzgError.getRuntimeException("078", exchangeName);
}
return ret;
}
......
......@@ -7,6 +7,7 @@ import com.yanzuoguang.mq.vo.MessagePlan;
import com.yanzuoguang.mq.vo.MessageVo;
import com.yanzuoguang.mq.vo.QueueVo;
import com.yanzuoguang.mq.vo.req.RegisterServerTokenReqVo;
import com.yanzuoguang.util.YzgError;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.DateHelper;
import com.yanzuoguang.util.helper.JsonHelper;
......@@ -137,7 +138,7 @@ public class YzgMqProcedure implements InitializingBean {
if (prevUnit == null) {
prevUnit = YZG_MQ_SYSTEM_QUEUE_PLAN_MIN;
} else if (prevUnit.unit < mqConfig.getUnitMin()) {
throw new CodeException("算法错误");
throw YzgError.getRuntimeException("079");
}
// 返回最大时间的队列
return prevUnit;
......
......@@ -6,6 +6,7 @@ import com.yanzuoguang.mq.service.MessageLogService;
import com.yanzuoguang.mq.vo.MessageLogVo;
import com.yanzuoguang.mq.vo.req.MessageLogRemoveReqVo;
import com.yanzuoguang.mq.vo.req.MessageLogReqVo;
import com.yanzuoguang.util.YzgError;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.JsonHelper;
import com.yanzuoguang.util.helper.StringHelper;
......@@ -71,7 +72,7 @@ public class MessageLogServiceImpl implements MessageLogService {
public String log() {
Message message = localMessage.get();
if (message == null) {
throw new CodeException("当前队列没有消息");
throw YzgError.getRuntimeException("080");
}
MessageProperties messageProperties = message.getMessageProperties();
return this.log(new MessageLogReqVo(messageProperties.getConsumerQueue(), messageProperties.getMessageId()));
......@@ -86,12 +87,12 @@ public class MessageLogServiceImpl implements MessageLogService {
@Override
public String log(MessageLogReqVo req) {
if (StringHelper.isEmpty(req.getMessageId()) || StringHelper.isEmpty(req.getQueue())) {
throw new CodeException("请传入queue和messageId");
throw YzgError.getRuntimeException("082");
}
MessageLogRemoveReqVo loadReq = new MessageLogRemoveReqVo(req.getQueue(), req.getMessageId());
MessageLogVo load = messageLogDao.load(loadReq, MessageLogVo.class);
if (load != null) {
throw new CodeException("消息队列" + req.getQueue() + "消息" + req.getMessageId() + "已经执行");
throw YzgError.getRuntimeException("081", req.getQueue(), req.getMessageId());
}
load = JsonHelper.to(req, MessageLogVo.class);
messageLogDao.create(load);
......@@ -107,7 +108,7 @@ public class MessageLogServiceImpl implements MessageLogService {
@Override
public String logRemove(MessageLogRemoveReqVo req) {
if (StringHelper.isEmpty(req.getMessageId()) || StringHelper.isEmpty(req.getQueue())) {
throw new CodeException("请传入queue和messageId");
throw YzgError.getRuntimeException("082");
}
messageLogDao.remove(req);
return req.getMessageId();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment