mirror of
https://github.com/zfile-dev/zfile.git
synced 2025-04-19 05:34:52 +00:00
🐛 修复通过 nginx 反向代理后, 未登录后台时请求, 重定向到反代前地址的 bug
This commit is contained in:
1 parent
43aba8e20e
commit
8d30ca7eee
1 file changed
+1
-1
@@ -1 +1 @@
|
||||
package im.zhaojun.zfile.common.exception;
import cn.dev33.satoken.exception.NotLoginException;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import im.zhaojun.zfile.admin.exception.ForbidFileOperationException;
import im.zhaojun.zfile.admin.exception.StorageSourceAutoConfigCorsException;
import im.zhaojun.zfile.common.exception.file.operator.GetFileInfoException;
import im.zhaojun.zfile.common.exception.file.operator.ProxyDownloadFileException;
import im.zhaojun.zfile.common.util.AjaxJson;
import im.zhaojun.zfile.common.util.RequestHolder;
import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.connector.ClientAbortException;
import org.springframework.http.HttpStatus;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.validation.BindException;
import org.springframework.validation.BindingResult;
import org.springframework.web.HttpMediaTypeNotAcceptableException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
* 全局异常处理
*
* @author zhaojun
*/
@ControllerAdvice
@Slf4j
public class GlobalException {
@ExceptionHandler({IllegalDownloadLinkException.class})
@ResponseBody
@ResponseStatus(HttpStatus.FORBIDDEN)
public AjaxJson<String> getFileInfoException(IllegalDownloadLinkException e) {
return AjaxJson.getError(e.getMessage());
}
@ExceptionHandler({GetFileInfoException.class})
@ResponseBody
@ResponseStatus(HttpStatus.BAD_REQUEST)
public AjaxJson<String> getFileInfoException(GetFileInfoException e) {
log.error("获取文件信息异常 {}. 存储源 ID: {}, 文件路径: {}", e.getMessage(), e.getStorageId(), e.getPathAndName());
return AjaxJson.getError("获取文件信息异常, 请联系管理员");
}
@ExceptionHandler({ProxyDownloadFileException.class})
@ResponseBody
@ResponseStatus(HttpStatus.BAD_REQUEST)
public AjaxJson<String> proxyDownloadFileException(ProxyDownloadFileException e) {
log.error("代理下载文件异常 {}. 存储源 ID: {}, 下载路径: {}", e.getMessage(), e.getStorageId(), e.getPathAndName());
return AjaxJson.getError("下载文件异常, 请联系管理员!");
}
@ExceptionHandler({LoginVerifyException.class})
@ResponseBody
@ResponseStatus(HttpStatus.FORBIDDEN)
public AjaxJson<String> loginVerifyException(LoginVerifyException e) {
return AjaxJson.getError(e.getMessage());
}
@ExceptionHandler({StorageSourceNotSupportProxyUploadException.class})
@ResponseBody
@ResponseStatus(HttpStatus.BAD_REQUEST)
public AjaxJson<String> storageSourceNotSupportProxyUploadException(StorageSourceNotSupportProxyUploadException e) {
return AjaxJson.getError("非法操作, 当前存储源不支持此方式上传.");
}
@ExceptionHandler({DisableProxyDownloadException.class})
@ResponseBody
@ResponseStatus(HttpStatus.BAD_REQUEST)
public AjaxJson<String> disableProxyDownloadException(DisableProxyDownloadException e) {
return AjaxJson.getError("非法操作, 当前文件不支持此类下载方式.");
}
@ExceptionHandler({UnsupportedOperationException.class})
@ResponseBody
@ResponseStatus(HttpStatus.BAD_REQUEST)
public AjaxJson<String> handleFileUploadException(UnsupportedOperationException e) {
return AjaxJson.getError(e.getMessage());
}
@ExceptionHandler({FileUploadException.class})
@ResponseBody
@ResponseStatus(HttpStatus.UNAUTHORIZED)
public AjaxJson<String> handleFileUploadException(FileUploadException e) {
if (log.isDebugEnabled()) {
log.debug("上传文件失败: 存储类型: {}, 存储源 id: {}, 存储源路径: {}",
e.getStorageTypeEnum(), e.getStorageId(), e.getPath(), e);
}
return AjaxJson.getError("上传失败");
}
@ExceptionHandler({FileAccessException.class})
@ResponseBody
@ResponseStatus(HttpStatus.UNAUTHORIZED)
public AjaxJson<String> handleFileAccessException(FileAccessException e) {
return AjaxJson.getError(e.getMessage());
}
@ExceptionHandler({HttpMessageNotReadableException.class})
@ResponseBody
@ResponseStatus(HttpStatus.BAD_REQUEST)
public AjaxJson<String> handlerHttpMessageNotReadableException(HttpMessageNotReadableException e) {
return AjaxJson.getBadRequestError("请求参数不合法");
}
@ExceptionHandler({NotEnabledStorageSourceException.class})
@ResponseStatus(HttpStatus.FORBIDDEN)
@ResponseBody
public AjaxJson<String> Line truncated
|
||||
package im.zhaojun.zfile.common.exception;
import cn.dev33.satoken.exception.NotLoginException;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import im.zhaojun.zfile.admin.exception.ForbidFileOperationException;
import im.zhaojun.zfile.admin.exception.StorageSourceAutoConfigCorsException;
import im.zhaojun.zfile.admin.service.SystemConfigService;
import im.zhaojun.zfile.common.exception.file.operator.GetFileInfoException;
import im.zhaojun.zfile.common.exception.file.operator.ProxyDownloadFileException;
import im.zhaojun.zfile.common.util.AjaxJson;
import im.zhaojun.zfile.common.util.RequestHolder;
import im.zhaojun.zfile.common.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.connector.ClientAbortException;
import org.springframework.http.HttpStatus;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.validation.BindException;
import org.springframework.validation.BindingResult;
import org.springframework.web.HttpMediaTypeNotAcceptableException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
* 全局异常处理
*
* @author zhaojun
*/
@ControllerAdvice
@Slf4j
public class GlobalException {
@Resource
private SystemConfigService systemConfigService;
@ExceptionHandler({IllegalDownloadLinkException.class})
@ResponseBody
@ResponseStatus(HttpStatus.FORBIDDEN)
public AjaxJson<String> getFileInfoException(IllegalDownloadLinkException e) {
return AjaxJson.getError(e.getMessage());
}
@ExceptionHandler({GetFileInfoException.class})
@ResponseBody
@ResponseStatus(HttpStatus.BAD_REQUEST)
public AjaxJson<String> getFileInfoException(GetFileInfoException e) {
log.error("获取文件信息异常 {}. 存储源 ID: {}, 文件路径: {}", e.getMessage(), e.getStorageId(), e.getPathAndName());
return AjaxJson.getError("获取文件信息异常, 请联系管理员");
}
@ExceptionHandler({ProxyDownloadFileException.class})
@ResponseBody
@ResponseStatus(HttpStatus.BAD_REQUEST)
public AjaxJson<String> proxyDownloadFileException(ProxyDownloadFileException e) {
log.error("代理下载文件异常 {}. 存储源 ID: {}, 下载路径: {}", e.getMessage(), e.getStorageId(), e.getPathAndName());
return AjaxJson.getError("下载文件异常, 请联系管理员!");
}
@ExceptionHandler({LoginVerifyException.class})
@ResponseBody
@ResponseStatus(HttpStatus.FORBIDDEN)
public AjaxJson<String> loginVerifyException(LoginVerifyException e) {
return AjaxJson.getError(e.getMessage());
}
@ExceptionHandler({StorageSourceNotSupportProxyUploadException.class})
@ResponseBody
@ResponseStatus(HttpStatus.BAD_REQUEST)
public AjaxJson<String> storageSourceNotSupportProxyUploadException(StorageSourceNotSupportProxyUploadException e) {
return AjaxJson.getError("非法操作, 当前存储源不支持此方式上传.");
}
@ExceptionHandler({DisableProxyDownloadException.class})
@ResponseBody
@ResponseStatus(HttpStatus.BAD_REQUEST)
public AjaxJson<String> disableProxyDownloadException(DisableProxyDownloadException e) {
return AjaxJson.getError("非法操作, 当前文件不支持此类下载方式.");
}
@ExceptionHandler({UnsupportedOperationException.class})
@ResponseBody
@ResponseStatus(HttpStatus.BAD_REQUEST)
public AjaxJson<String> handleFileUploadException(UnsupportedOperationException e) {
return AjaxJson.getError(e.getMessage());
}
@ExceptionHandler({FileUploadException.class})
@ResponseBody
@ResponseStatus(HttpStatus.UNAUTHORIZED)
public AjaxJson<String> handleFileUploadException(FileUploadException e) {
if (log.isDebugEnabled()) {
log.debug("上传文件失败: 存储类型: {}, 存储源 id: {}, 存储源路径: {}",
e.getStorageTypeEnum(), e.getStorageId(), e.getPath(), e);
}
return AjaxJson.getError("上传失败");
}
@ExceptionHandler({FileAccessException.class})
@ResponseBody
@ResponseStatus(HttpStatus.UNAUTHORIZED)
public AjaxJson<String> handleFileAccessException(FileAccessException e) {
return AjaxJson.getError(e.getMessage());
}
@ExceptionHandler({HttpMessageNotReadableException.class})
@ResponseBody
@ResponseStatus(HttpStatus.BAD_REQUEST)
public AjaxJson<String> handlerHttpMessageNotReadableException(HttpMessageNotReadableException e) {
retLine truncated
|
||||
Reference in new issue
Block a user