Commit ded82077 authored by jiaorz's avatar jiaorz

1

parent 2dbcd72b
...@@ -19,6 +19,8 @@ import org.springframework.web.context.request.WebRequest; ...@@ -19,6 +19,8 @@ import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.io.StringWriter;
import static org.springframework.http.HttpStatus.NOT_EXTENDED; import static org.springframework.http.HttpStatus.NOT_EXTENDED;
...@@ -75,6 +77,14 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler { ...@@ -75,6 +77,14 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
public BaseResponse otherExceptionHandler(HttpServletResponse response, Exception ex) { public BaseResponse otherExceptionHandler(HttpServletResponse response, Exception ex) {
response.setStatus(500); response.setStatus(500);
logger.error(ex.getMessage(),ex); logger.error(ex.getMessage(),ex);
Throwable cause = ex.getCause();
if(cause != null && cause.toString().contains("Exception")) {
StringWriter stringWriter = new StringWriter();
cause.printStackTrace(new PrintWriter(stringWriter));
logger.error(cause.getMessage(), ex);
HttpRequestUtil.httpGet("http://10.5.52.3:8765/api/universal/mail/app/unauth/send?toUser=jiaoruizhen@126.com&subject=服务器异常&content=" + stringWriter.toString());
return new BaseResponse(5000, "Server exception: " + ex.getMessage());
}
HttpRequestUtil.httpGet("http://10.5.52.3:8765/api/universal/mail/app/unauth/send?toUser=jiaoruizhen@126.com&subject=服务器异常&content=" + ex); HttpRequestUtil.httpGet("http://10.5.52.3:8765/api/universal/mail/app/unauth/send?toUser=jiaoruizhen@126.com&subject=服务器异常&content=" + ex);
return new BaseResponse(CommonConstants.EX_OTHER_CODE, ex.getMessage()); return new BaseResponse(CommonConstants.EX_OTHER_CODE, ex.getMessage());
} }
......
...@@ -9,6 +9,9 @@ import lombok.extern.slf4j.Slf4j; ...@@ -9,6 +9,9 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.bind.annotation.RestControllerAdvice;
import java.io.PrintWriter;
import java.io.StringWriter;
@RestControllerAdvice("com.xxfc.platform") @RestControllerAdvice("com.xxfc.platform")
@Slf4j @Slf4j
public class PlatformExceptionHandler { public class PlatformExceptionHandler {
...@@ -25,10 +28,13 @@ public class PlatformExceptionHandler { ...@@ -25,10 +28,13 @@ public class PlatformExceptionHandler {
//服务器异常 //服务器异常
@ExceptionHandler(Exception.class) @ExceptionHandler(Exception.class)
public ObjectRestResponse<?> exceptionHandler(Exception e){ public ObjectRestResponse<?> exceptionHandler(Exception e){
Throwable cause = e.getCause(); Throwable cause = e.getCause();
if(cause != null && cause.toString().contains("Exception")) { if(cause != null && cause.toString().contains("Exception")) {
StringWriter stringWriter = new StringWriter();
cause.printStackTrace(new PrintWriter(stringWriter));
log.error(cause.getMessage(), e); log.error(cause.getMessage(), e);
HttpRequestUtil.httpGet("http://10.5.52.3:8765/api/universal/mail/app/unauth/send?toUser=jiaoruizhen@126.com&subject=服务器异常&content=" + e); HttpRequestUtil.httpGet("http://10.5.52.3:8765/api/universal/mail/app/unauth/send?toUser=jiaoruizhen@126.com&subject=服务器异常&content=" + stringWriter.toString());
return assembleResult(ObjectRestResponse.createFailedResult(5000, "服务器开小差了,请稍后重试!"), "Server exception: " + e.getMessage()); return assembleResult(ObjectRestResponse.createFailedResult(5000, "服务器开小差了,请稍后重试!"), "Server exception: " + e.getMessage());
} }
log.error("Server exception: ", e); log.error("Server exception: ", e);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment