package com.qmth.boot.core.retrofit.exception;

import org.apache.commons.lang3.StringUtils;

/**
 * Retrofit调用响应错误
 */
public class RetrofitResponseError extends RuntimeException {

    private static final long serialVersionUID = 2146534139282835176L;

    private static final String MESSSAGE_FORMAT = "code=%s, body=%s";

    private int code;

    private String body;

    public RetrofitResponseError(int code, String body) {
        super(String.format(MESSSAGE_FORMAT, code, StringUtils.trimToEmpty(body)));
        this.code = code;
        this.body = body;
    }

    public RetrofitResponseError(int code, String body, Throwable cause) {
        super(String.format(MESSSAGE_FORMAT, code, StringUtils.trimToEmpty(body)), cause);
        this.code = code;
        this.body = body;
    }

    public int getCode() {
        return code;
    }

    public String getBody() {
        return body;
    }
}
