All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gitee.easyopen.exception.ApiException Maven / Gradle / Ivy

Go to download

easyopen mini版,保留基本签名校验,文档功能。https://gitee.com/durcframework/easyopen

There is a newer version: 1.0.4
Show newest version
package com.gitee.easyopen.exception;

import com.gitee.easyopen.message.Error;
import com.gitee.easyopen.message.Errors;

/**
 * @author tanghc
 */
public class ApiException extends RuntimeException {
    private static final long serialVersionUID = 16789476595630713L;
    private static final String ERROR_CODE = Errors.SYS_ERROR.getCode();

    private String code = ERROR_CODE;
    private Object data;

    public ApiException(String msg) {
        super(msg);
    }

    public ApiException(Exception e) {
        super(e);
    }

    public ApiException(Error error) {
        this(error.getMsg());
        this.code = error.getCode();
    }

    public ApiException(String msg, String code) {
        super(msg);
        this.code = code;
    }

    public ApiException(String msg, String code, Object data) {
        super(msg);
        this.code = code;
        this.data = data;
    }

    public ApiException(Error error, Object data) {
        this(error);
        this.data = data;
    }

    public String getCode() {
        return code;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
    
    /**
     * 获取RuntimeException异常,在做dubbo服务时可以用到,因为dubbo处理自定义异常有问题。
     */
    public RuntimeException getRuntimeException() {
        return new RuntimeException(this.getMessage());
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy