Progr1mmer 6 anni fa
parent
commit
1937c3e171

+ 13 - 12
common/common-exception/src/main/java/com/yihu/jw/exception/ApiException.java

@ -22,19 +22,8 @@ package com.yihu.jw.exception;
 * @created 2015.12.20 16:05
 */
public class ApiException extends RuntimeException {
    private Integer errorCode = -10000;
    public Integer getErrorCode() {
        return errorCode;
    }
    public void setErrorCode(Integer errorCode) {
        this.errorCode = errorCode;
    }
    public ApiException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
        super(message, cause, enableSuppression, writableStackTrace);
    }
    private Integer errorCode = -10000;
    public ApiException() {
    }
@ -55,4 +44,16 @@ public class ApiException extends RuntimeException {
    public ApiException(Throwable cause) {
        super(cause);
    }
    public ApiException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
        super(message, cause, enableSuppression, writableStackTrace);
    }
    public Integer getErrorCode() {
        return errorCode;
    }
    public void setErrorCode(Integer errorCode) {
        this.errorCode = errorCode;
    }
}

+ 4 - 0
common/common-web/pom.xml

@ -37,6 +37,10 @@
            <groupId>com.yihu.jw</groupId>
            <artifactId>common-rest-model</artifactId>
        </dependency>
        <dependency>
            <groupId>com.yihu.jw</groupId>
            <artifactId>common-exception</artifactId>
        </dependency>
    </dependencies>
</project>

+ 0 - 20
common/common-web/src/main/java/com/yihu/jw/web/exception/ApiException.java

@ -1,20 +0,0 @@
package com.yihu.jw.web.exception;
import org.springframework.util.Assert;
public class ApiException extends RuntimeException {
    private int errorCode = -10000; //错误码
    public ApiException(String message) {
        this(message, 500);
    }
    public ApiException(String message, int errorCode) {
        super(message);
        this.errorCode = errorCode;
        Assert.state(errorCode != 200, "The error code cannot be equal to 200");
    }
}

+ 2 - 2
common/common-web/src/main/java/com/yihu/jw/web/handler/GlobalExceptionHandler.java

@ -1,7 +1,7 @@
package com.yihu.jw.web.handler;
import com.yihu.jw.exception.ApiException;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.web.exception.ApiException;
import feign.FeignException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -47,7 +47,7 @@ public class GlobalExceptionHandler {
            envelop.setStatus(HttpStatus.BAD_GATEWAY.value());
        } else if (e instanceof ApiException) { //业务逻辑异常
            ApiException apiException = (ApiException) e;
            envelop.setMessage(apiException.getErrorDesc());
            envelop.setMessage(apiException.getMessage());
            envelop.setStatus(apiException.getErrorCode());
            return envelop; //此异常不进行日志记录
        } else {