...
|
...
|
@@ -9,6 +9,7 @@ import com.yohoufo.common.exception.SessionExpireException; |
|
|
import com.yohoufo.common.exception.UfoServiceException;
|
|
|
import com.yohoufo.common.utils.ServletUtils;
|
|
|
import org.apache.commons.httpclient.HttpStatus;
|
|
|
import org.apache.commons.lang3.tuple.Pair;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.web.bind.MissingServletRequestParameterException;
|
...
|
...
|
@@ -76,9 +77,11 @@ public class GlobalDefaultExceptionHandler { |
|
|
serviceName, code, desc, request.getRequestURI(), serviceName, params);
|
|
|
} else if (e instanceof ServiceException) { //服务异常,不能直接返回给客户端,必须映射一下
|
|
|
ServiceException serviceException = (ServiceException) e;
|
|
|
ServiceError serviceError = serviceException.getServiceError();
|
|
|
code = serviceError.getMappingGatewayError().getLeft();
|
|
|
desc = serviceError.getMappingGatewayError().getRight();
|
|
|
|
|
|
Pair<Integer, String> codeMsgPair = getMessageCode((ServiceException) e);
|
|
|
code = codeMsgPair.getLeft();
|
|
|
desc = codeMsgPair.getRight();
|
|
|
|
|
|
if (serviceException.getParams() != null) {
|
|
|
desc = MessageFormat.format(desc, serviceException.getParams());
|
|
|
}
|
...
|
...
|
@@ -107,4 +110,21 @@ public class GlobalDefaultExceptionHandler { |
|
|
}
|
|
|
|
|
|
|
|
|
private Pair<Integer, String> getMessageCode(ServiceException serviceException){
|
|
|
|
|
|
ServiceError serviceError = serviceException.getServiceError();
|
|
|
|
|
|
// 该service是OTHER_ERROR 报错[系统异常]
|
|
|
if (serviceError == ServiceError.OTHER_ERROR){
|
|
|
|
|
|
// ex. servcieException[400, 优惠券领取中] servcie[500,系统异常]
|
|
|
if (serviceException.getCode() != serviceError.getCode()){
|
|
|
return Pair.of(serviceException.getCode(), serviceException.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return Pair.of(serviceError.getMappingGatewayError().getLeft(), serviceError.getMappingGatewayError().getRight());
|
|
|
}
|
|
|
|
|
|
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|