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

com.qiniu.common.QiniuException Maven / Gradle / Ivy

There is a newer version: 7.2.29.3
Show newest version
package com.qiniu.common;

import com.qiniu.http.Error;
import com.qiniu.http.Response;

import java.io.IOException;

/**
 * 七牛SDK异常封装类,封装了http响应数据
 */
public final class QiniuException extends IOException {
    public final Response response;
    private String error;


    public QiniuException(Response response) {
        super(response != null ? response.getInfo() : null);
        this.response = response;
        if (response != null) {
            response.close();
        }
    }

    public QiniuException(Exception e) {
        this(e, null);
    }

    public QiniuException(Exception e, String msg) {
        super(msg, e);
        this.response = null;
        this.error = msg;
    }

    public String url() {
        return response.url();
    }

    public int code() {
        return response == null ? -1 : response.statusCode;
    }

    public String error() {
        if (error != null) {
            return error;
        }
        if (response == null || response.statusCode / 100 == 2 || !response.isJson()) {
            return null;
        }
        Error e = null;
        try {
            e = response.jsonToObject(Error.class);
        } catch (QiniuException e1) {
            e1.printStackTrace();
        }
        error = e == null ? "" : e.error;
        return error;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy