package com.panzhihua.zuul.handles;
|
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
|
import org.apache.tomcat.util.http.fileupload.impl.FileSizeLimitExceededException;
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.multipart.MaxUploadSizeExceededException;
|
|
import com.panzhihua.common.constants.HttpStatus;
|
import com.panzhihua.common.model.vos.R;
|
import com.panzhihua.common.utlis.ResultUtil;
|
|
@ControllerAdvice
|
public class FileUploadExceptionAdvice {
|
|
@ExceptionHandler(MaxUploadSizeExceededException.class)
|
public void handleMaxSizeException(MaxUploadSizeExceededException exc, HttpServletRequest request,
|
HttpServletResponse response) {
|
// 请求超过大小限制
|
response.setContentType("application/json;charset=utf-8");
|
ResultUtil.responseJson(response, R.fail(HttpStatus.REQUEST_TOO_LARGE, "请求主体的大小超过限制"));
|
return;
|
|
}
|
|
@ExceptionHandler(FileSizeLimitExceededException.class)
|
public void handleFileSizeLimitException(FileSizeLimitExceededException exc, HttpServletRequest request,
|
HttpServletResponse response) {
|
// 请求超过大小限制
|
response.setContentType("application/json;charset=utf-8");
|
ResultUtil.responseJson(response, R.fail(HttpStatus.REQUEST_TOO_LARGE, "文件大小超过限制"));
|
return;
|
}
|
|
}
|