|
|
@@ -1,5 +1,8 @@
|
|
|
package com.usoftchina.saas.gateway.error;
|
|
|
|
|
|
+import com.usoftchina.saas.exception.BaseException;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.boot.autoconfigure.web.ErrorProperties;
|
|
|
import org.springframework.boot.autoconfigure.web.ResourceProperties;
|
|
|
import org.springframework.boot.autoconfigure.web.reactive.error.DefaultErrorWebExceptionHandler;
|
|
|
@@ -20,6 +23,8 @@ import java.util.Map;
|
|
|
*/
|
|
|
public class MyExceptionHandler extends DefaultErrorWebExceptionHandler {
|
|
|
|
|
|
+ private Logger logger = LoggerFactory.getLogger(MyExceptionHandler.class);
|
|
|
+
|
|
|
public MyExceptionHandler(ErrorAttributes errorAttributes, ResourceProperties resourceProperties,
|
|
|
ErrorProperties errorProperties, ApplicationContext applicationContext) {
|
|
|
super(errorAttributes, resourceProperties, errorProperties, applicationContext);
|
|
|
@@ -32,10 +37,16 @@ public class MyExceptionHandler extends DefaultErrorWebExceptionHandler {
|
|
|
protected Map<String, Object> getErrorAttributes(ServerRequest request, boolean includeStackTrace) {
|
|
|
int code = 500;
|
|
|
Throwable error = super.getError(request);
|
|
|
+ String message = error.getMessage();
|
|
|
if (error instanceof NotFoundException) {
|
|
|
code = 404;
|
|
|
+ } else if (error instanceof BaseException) {
|
|
|
+ BaseException e = (BaseException) error;
|
|
|
+ code = e.getCode();
|
|
|
+ message = e.getMessage();
|
|
|
}
|
|
|
- return response(code, this.buildMessage(request, error));
|
|
|
+ logger.error(this.buildMessage(request, error));
|
|
|
+ return response(code, message);
|
|
|
}
|
|
|
|
|
|
/**
|