修改统一异常处理

This commit is contained in:
付庆吉
2021-02-25 18:39:24 +08:00
parent 3f021a20ac
commit 2050ea2cd3

View File

@ -60,7 +60,7 @@ public class BusinessExceptionHandlerAdvice {
//堆栈信息转为字符串
log.info(ExceptionUtil.stacktraceToString(exception));
Map<String, Object> body = new HashMap<>();
body.put("path", request.getRequestURI());
// body.put("path", request.getRequestURI());
return BaseResponse.fail(exception.getCode(), exception.getMessage(), Convert.toStr(body));
}
@ -90,7 +90,7 @@ public class BusinessExceptionHandlerAdvice {
Map<String, Object> body = new HashMap<>();
body.put("errors", JsonUtils.objectToJson(invalidArguments));
body.put("error", HttpStatus.BAD_REQUEST.getReasonPhrase());
body.put("path", request.getRequestURI());
// body.put("path", request.getRequestURI());
return BaseResponse.fail(HttpStatus.BAD_REQUEST.value(), "参数验证错误", Convert.toStr(body));
}
@ -118,7 +118,7 @@ public class BusinessExceptionHandlerAdvice {
Map<String, Object> body = new HashMap<>();
body.put("errors", JsonUtils.objectToJson(invalidArguments));
body.put("error", HttpStatus.BAD_REQUEST.getReasonPhrase());
body.put("path", request.getRequestURI());
// body.put("path", request.getRequestURI());
return BaseResponse.fail(HttpStatus.BAD_REQUEST.value(), "参数错误", Convert.toStr(body));
}
@ -135,7 +135,7 @@ public class BusinessExceptionHandlerAdvice {
Map<String, Object> body = new HashMap<>();
body.put("errors", exception.getMessage());
body.put("error", HttpStatus.METHOD_NOT_ALLOWED.getReasonPhrase());
body.put("path", request.getRequestURI());
// body.put("path", request.getRequestURI());
return BaseResponse.fail(HttpStatus.METHOD_NOT_ALLOWED.value(), "错误的请求方式", Convert.toStr(body));
}
@ -152,8 +152,8 @@ public class BusinessExceptionHandlerAdvice {
Map<String, Object> body = new HashMap<>();
body.put("errors", exception.getMessage());
body.put("error", HttpStatus.BAD_REQUEST.getReasonPhrase());
body.put("path", request.getRequestURI());
return BaseResponse.fail(HttpStatus.BAD_REQUEST.value(), "参数缺失", Convert.toStr(body));
// body.put("path", request.getRequestURI());
return BaseResponse.fail(HttpStatus.BAD_REQUEST.value(), "参数缺失" + exception.getMessage(), Convert.toStr(body));
}
// ----------------------------data--------------------------------------
@ -172,8 +172,8 @@ public class BusinessExceptionHandlerAdvice {
Map<String, Object> body = new HashMap<>();
body.put("errors", exception.getMessage());
body.put("error", HttpStatus.BAD_REQUEST.getReasonPhrase());
body.put("path", request.getRequestURI());
return BaseResponse.fail(HttpStatus.BAD_REQUEST.value(), "数据库异常", Convert.toStr(body));
// body.put("path", request.getRequestURI());
return BaseResponse.fail(HttpStatus.BAD_REQUEST.value(), "数据库异常" + exception.getMessage(), Convert.toStr(body));
}
/**
@ -189,7 +189,7 @@ public class BusinessExceptionHandlerAdvice {
Map<String, Object> body = new HashMap<>();
body.put("errors", exception.getMessage());
body.put("error", HttpStatus.BAD_REQUEST.getReasonPhrase());
body.put("path", request.getRequestURI());
// body.put("path", request.getRequestURI());
return BaseResponse.fail(HttpStatus.BAD_REQUEST.value(), "数据不存在", Convert.toStr(body));
}
@ -206,7 +206,7 @@ public class BusinessExceptionHandlerAdvice {
Map<String, Object> body = new HashMap<>();
body.put("errors", exception.getMessage());
body.put("error", HttpStatus.BAD_REQUEST.getReasonPhrase());
body.put("path", request.getRequestURI());
// body.put("path", request.getRequestURI());
return BaseResponse.fail(HttpStatus.BAD_REQUEST.value(), "数据重复插入", Convert.toStr(body));
}
@ -223,7 +223,7 @@ public class BusinessExceptionHandlerAdvice {
Map<String, Object> body = new HashMap<>();
body.put("errors", exception.getMessage());
body.put("error", HttpStatus.BAD_REQUEST.getReasonPhrase());
body.put("path", request.getRequestURI());
// body.put("path", request.getRequestURI());
return BaseResponse.fail(HttpStatus.BAD_REQUEST.value(), "参数类型不匹配", Convert.toStr(body));
}
@ -242,8 +242,8 @@ public class BusinessExceptionHandlerAdvice {
Map<String, Object> body = new HashMap<>();
body.put("errors", exception.getMessage());
body.put("error", HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
body.put("path", request.getRequestURI());
return BaseResponse.fail(HttpStatus.INTERNAL_SERVER_ERROR.value(), "网络异常", Convert.toStr(body));
// body.put("path", request.getRequestURI());
return BaseResponse.fail(HttpStatus.INTERNAL_SERVER_ERROR.value(), "系统异常" + exception.getMessage(), Convert.toStr(body));
}
/**