package cn.com.qmth.stmms.api.exception;

public class ApiException extends RuntimeException {

    private static final long serialVersionUID = -4952288587291887490L;

    private int code;

    private ApiException(int code, String message) {
        super(message);
        this.code = code;
    }

    public int getCode() {
        return code;
    }

    public ApiException replaceMessage(String message) {
        return new ApiException(this.code, message);
    }

    public ApiException appendMessage(String message) {
        return new ApiException(this.code, this.getMessage() + message);
    }

    public static final ApiException AUTHORIZATION_UNEXIST = new ApiException(401, "authorization unexists");

    public static final ApiException SIGNATURE_INVALID = new ApiException(401, "signature invalid");

    public static final ApiException USER_DISABLED = new ApiException(401, "user disabled");

    public static final ApiException USER_ROLE_INVALID = new ApiException(401, "user's role invalid");

    public static final ApiException EXAM_NOT_ACCESSIBLED = new ApiException(401, "user cannot access specified exam");

    public static final ApiException QUERY_PARAM_ERROR = new ApiException(400, "query param error");

    public static final ApiException USER_LOGIN_FAILE = new ApiException(500, "user login faile");

    public static final ApiException FILE_UPLOAD_ERROR = new ApiException(500, "file upload error");

    public static final ApiException FORMAT_TYPE_ERROR = new ApiException(500, "format type error");

    public static final ApiException SCHOOL_NOT_ACCESSIBLED = new ApiException(401, "user cannot access school");

}
