系统异常处理

This commit is contained in:
钱涛 2022-07-01 15:18:29 +08:00
parent 6262aeeb01
commit c372fff59c
2 changed files with 33 additions and 20 deletions

View File

@ -54,7 +54,7 @@ public class ResponseResult<T, R> {
return Error(cause.getMessage());
} catch (Exception e) {
log.error("salary api run fail", e);
return Error(e.getMessage());
return Error("系统异常!");
}
}
@ -76,7 +76,7 @@ public class ResponseResult<T, R> {
return Error(cause.getMessage());
} catch (Exception e) {
log.error("salary api run fail", e);
return Error(e.getMessage());
return Error("系统异常!", e);
}
}
@ -98,23 +98,10 @@ public class ResponseResult<T, R> {
return Error(cause.getMessage());
} catch (Exception e) {
log.error("salary api run fail", e);
return Error(e.getMessage());
return Error("系统异常!", e);
}
}
/**
* 成功返回
*/
private String Ok(R r) {
Map<String, Object> apidatas = new HashMap<>();
apidatas.put("status", true);
apidatas.put("data", r);
String success = getJsonString(apidatas);
if (isLog) {
log.info("run salary api success return {}", success);
}
return success;
}
private static String getJsonString(Object apidatas) {
ObjectMapper mapper = new ObjectMapper();
@ -137,6 +124,21 @@ public class ResponseResult<T, R> {
}
/**
* 成功返回
*/
private String Ok(R r) {
Map<String, Object> apidatas = new HashMap<>();
apidatas.put("status", true);
apidatas.put("data", r);
String success = getJsonString(apidatas);
if (isLog) {
log.info("run salary api success return {}", success);
}
return success;
}
/**
* 失败返回
*/
@ -148,4 +150,15 @@ public class ResponseResult<T, R> {
}
/**
* 系统异常失败返回
*/
private static String Error(String message, Exception e) {
Map<String, Object> apidatas = new HashMap<>();
apidatas.put("status", false);
apidatas.put("errormsg", message);
apidatas.put("error", e.getMessage());
return JSONObject.toJSONString(apidatas, SerializerFeature.DisableCircularReferenceDetect);
}
}

View File

@ -132,8 +132,8 @@ public class TaxAgentController {
/**
* 获取个税扣缴义务人表单
*
* @param id
* @return
* @param id 表单id
* @return 表单对象
*/
@GET
@Path("/getForm")
@ -146,8 +146,8 @@ public class TaxAgentController {
/**
* 新建个税扣缴义务人
*
* @param saveParam
* @return
* @param saveParam 个税扣缴义务人保存参数
* @return 个税扣缴义务人id
*/
@POST
@Path("/save")