|
|
|
@ -58,19 +58,19 @@ public class Result implements Serializable { |
|
|
|
} |
|
|
|
|
|
|
|
//失败响应 自定义状态码 默认为500 |
|
|
|
public static Result error(BusinessException e) { |
|
|
|
public static Result error(Exception e) { |
|
|
|
Result response = new Result(); |
|
|
|
// 定义默认错误码映射 |
|
|
|
final int defaultErrorCode = 400; |
|
|
|
// 检查 getCode() 是否为 null(如果是 Integer) |
|
|
|
Integer code = e.getCode(); |
|
|
|
if (code == null || code == 0) { |
|
|
|
String code = e.getMessage(); |
|
|
|
if (code == null ) { |
|
|
|
response.setCode(defaultErrorCode); // 默认错误码 |
|
|
|
} else { |
|
|
|
response.setCode(code); |
|
|
|
response.setCode(500); |
|
|
|
} |
|
|
|
response.setMsg(e.getMessage()); |
|
|
|
return response; |
|
|
|
return Result.error(500, e.getMessage()); |
|
|
|
} |
|
|
|
public String toJson() throws JsonProcessingException { |
|
|
|
ObjectMapper mapper = new ObjectMapper(); |
|
|
|
|