Skip to content

Commit a6a82a2

Browse files
author
Vens Chen
committed
修复debug模式程序异常的bug
1 parent cb8517d commit a6a82a2

File tree

5 files changed

+13
-9
lines changed

5 files changed

+13
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ buildscript {
2525

2626
在app的gradle文件引用依赖:
2727
```
28-
compile 'com.github.chenthreetrees:thttp:1.0.6'
28+
compile 'com.github.chenthreetrees:thttp:1.0.7'
2929
```
3030

3131

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ dependencies {
3030

3131
compile project(":tthttp")
3232
compile 'com.github.chenthreetrees:tdialog:1.0.0'
33-
// compile 'com.github.chenthreetrees:thttp:1.0.5'
33+
// compile 'com.github.chenthreetrees:thttp:1.0.6'
3434
}

app/src/main/java/com/threetree/thttp/CommonPresenter.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@ public CommonPresenter(Context context,ILoadingView iLoadingView)
1919
{
2020
super(iLoadingView);
2121
mContext = context;
22-
// mApiService = RetrofitManager.getInstence().getRetrofitService(ApiService.class);
2322
mApiService = (ApiService)RetrofitManager.getInstence().getRetrofitService();
2423
}
2524

26-
2725
@Override
2826
protected void showError(ApiException ex)
2927
{

tthttp/src/main/java/com/threetree/tthttp/exception/ExceptionEngine.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static ApiException handleException(Throwable e){
5252
ApiException ex;
5353
if (e instanceof HttpException){ //HTTP错误
5454
HttpException httpException = (HttpException) e;
55-
ex = new ApiException(e, ERROR.HTTP_ERROR);
55+
ex = new ApiException(e, httpException.code());
5656
switch(httpException.code()){
5757
case UNAUTHORIZED:
5858
case FORBIDDEN:
@@ -91,7 +91,7 @@ else if (e instanceof ServerException){ //服务器返回的错误
9191
return ex;
9292
}else {
9393
ex = new ApiException(e, ERROR.UNKNOWN);
94-
ex.setDisplayMessage("未知错误"); //未知错误
94+
ex.setDisplayMessage("未知错误:" + e.getMessage()); //未知错误
9595
return ex;
9696
}
9797
}

tthttp/src/main/java/com/threetree/tthttp/interceptor/LogInterceptor.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import java.io.IOException;
88

99
import okhttp3.Interceptor;
10+
import okhttp3.MediaType;
1011
import okhttp3.Response;
12+
import okhttp3.ResponseBody;
1113

1214
/**
1315
* Created by Administrator on 2018/8/29.
@@ -17,9 +19,13 @@ public class LogInterceptor implements Interceptor {
1719
@Override
1820
public Response intercept(Chain chain) throws IOException
1921
{
20-
Response originalResponse = chain.proceed(chain.request());
22+
Response response = chain.proceed(chain.request());
23+
MediaType mediaType = response.body().contentType();
24+
String content= response.body().string();
2125
if(RetrofitManager.getInstence().isDebug())
22-
Log.d("response",originalResponse.body().string());
23-
return originalResponse;
26+
Log.d("response",content);
27+
return response.newBuilder()
28+
.body(ResponseBody.create(mediaType, content))
29+
.build();
2430
}
2531
}

0 commit comments

Comments
 (0)