响应格式:
json:
{
code: 100001, # 错误码
message: 未找到首页优惠券活动, # 错误信息
request: GET url # 请求方式、请求url
}
解决思路: 将异常拦截,然后封装成统一的格式(即类: UnifyResponse)
核心处理类:GlobalExceptionAdvice
@ControllerAdvice
public class GlobalExceptionAdvice{
@Autowired
private ExceptionCodeConfiguration codeConfiguration;
// 对HttpException异常进行处理
@ExceptionHandler(value = HttpException.class)
public ResponseEntity<UnfiyResponse> handleHttpException(HttpServerletRequest req, HttpException e){
// 请求url
String requestUrl = req.getRequestURI();
// 请求方法
String method