全局错误处理

This commit is contained in:
Captain.B 2020-03-04 11:30:22 +08:00
parent a1ba010375
commit 6a5c6a2d38
2 changed files with 6 additions and 3 deletions

View File

@ -24,8 +24,7 @@ public class RestControllerExceptionHandler {
@ExceptionHandler(MSException.class) @ExceptionHandler(MSException.class)
public ResultHolder msExceptionHandler(HttpServletRequest request, HttpServletResponse response, MSException e) { public ResultHolder msExceptionHandler(HttpServletRequest request, HttpServletResponse response, MSException e) {
// 自定义异常返回200 response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
response.setStatus(HttpStatus.OK.value());
return ResultHolder.error(e.getMessage()); return ResultHolder.error(e.getMessage());
} }
} }

View File

@ -48,7 +48,11 @@ export default {
function exception(error, result) { function exception(error, result) {
result.loading = false; result.loading = false;
window.console.error(error.response || error.message); window.console.error(error.response || error.message);
Message.error({message: error.message, showClose: true}); if (error.response.data) {
Message.error({message: error.response.data.message, showClose: true});
} else {
Message.error({message: error.message, showClose: true});
}
} }
Vue.prototype.$get = function (url, success) { Vue.prototype.$get = function (url, success) {