package com.qmth.boot.api.exception;

import org.springframework.http.HttpStatus;

/**
 * API层通用的异常描述，包含http状态吗，可转换为标准json返回格式
 */
public class ApiException extends RuntimeException {

    private static final long serialVersionUID = -6281803364896392700L;

    private HttpStatus status;

    private int code;

    private String error;

    private String message;

    public ApiException(HttpStatus status, int code, String error, String message) {
        this.status = status;
        this.code = code;
        this.error = error;
        this.message = message;
    }

    public HttpStatus getStatus() {
        return status;
    }

    public int getCode() {
        return code;
    }

    public String getError() {
        return error;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public ExceptionResponseEntity responseEntity() {
        return new ExceptionResponseEntity(code, error, message);
    }
}
