| | |
| | | package com.vincent.rsf.server.common.exception; |
| | | |
| | | import com.vincent.rsf.framework.common.R; |
| | | import com.vincent.rsf.framework.exception.CoolException; |
| | | import com.vincent.rsf.server.common.constant.Constants; |
| | | import com.vincent.rsf.server.common.utils.CommonUtil; |
| | | import org.slf4j.Logger; |
| | |
| | | @ExceptionHandler(BusinessException.class) |
| | | public R businessExceptionHandler(BusinessException e, HttpServletResponse response) { |
| | | CommonUtil.addCrossHeaders(response); |
| | | return R.parse(e.getMessage()); |
| | | } |
| | | |
| | | @ResponseBody |
| | | @ExceptionHandler(CoolException.class) |
| | | public R coolExceptionHandler(CoolException e, HttpServletResponse response) { |
| | | CommonUtil.addCrossHeaders(response); |
| | | return R.error(e.getMessage()); |
| | | } |
| | | |
| | | |
| | | @ResponseBody |
| | | @ExceptionHandler(Throwable.class) |
| | | public R exceptionHandler(Throwable e, HttpServletResponse response) { |
| | | logger.error(e.getMessage(), e); |
| | | CommonUtil.addCrossHeaders(response); |
| | | return R.error(Constants.RESULT_ERROR_MSG); |
| | | // 返回异常信息便于排查,避免仅返回 "Internal server error!" |
| | | String msg = e.getMessage() != null && !e.getMessage().isEmpty() ? e.getMessage() : e.getClass().getSimpleName(); |
| | | if (e.getCause() != null && e.getCause().getMessage() != null && !e.getCause().getMessage().isEmpty()) { |
| | | msg = msg + "; cause: " + e.getCause().getMessage(); |
| | | } |
| | | return R.error(msg); |
| | | } |
| | | |
| | | } |