Skip to content

Commit

Permalink
含Response的异常,打印默认展示Response信息
Browse files Browse the repository at this point in the history
  • Loading branch information
sxci committed Feb 24, 2017
1 parent c370b4f commit 62a4352
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/java/com/qiniu/common/QiniuException.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

import java.io.IOException;

Expand All @@ -14,6 +15,7 @@ public final class QiniuException extends IOException {


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

Expand All @@ -22,7 +24,7 @@ public QiniuException(Exception e) {
}

public QiniuException(Exception e, String msg) {
super(e);
super(msg, e);
this.response = null;
this.error = msg;
}
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/com/qiniu/http/Response.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,23 @@ public String url() {
public static class ErrorBody {
public String error;
}

public String getInfo() {
String[] msg = new String[3];
try {
msg[0] = this.url();
} catch (Throwable t) {
}
try {
msg[1] = this.toString();
} catch (Throwable t) {
}
try {
msg[2] = this.bodyString();
} catch (Throwable t) {

}

return StringUtils.join(msg, " \n");
}
}

0 comments on commit 62a4352

Please sign in to comment.