|
19 | 19 | import com.hjq.http.config.IRequestHandler; |
20 | 20 | import com.hjq.http.exception.CancelException; |
21 | 21 | import com.hjq.http.exception.DataException; |
| 22 | +import com.hjq.http.exception.FileMD5Exception; |
22 | 23 | import com.hjq.http.exception.HttpException; |
23 | 24 | import com.hjq.http.exception.NetworkException; |
24 | 25 | import com.hjq.http.exception.NullBodyException; |
@@ -61,9 +62,8 @@ public Object requestSucceed(@NonNull HttpRequest<?> httpRequest, @NonNull Respo |
61 | 62 | } |
62 | 63 |
|
63 | 64 | if (!response.isSuccessful()) { |
64 | | - // 返回响应异常 |
65 | | - throw new ResponseException(mApplication.getString(R.string.http_response_error) + ", responseCode: " + |
66 | | - response.code() + ", message: " + response.message(), response); |
| 65 | + throw new ResponseException(String.format(mApplication.getString(R.string.http_response_error), |
| 66 | + response.code(), response.message()), response); |
67 | 67 | } |
68 | 68 |
|
69 | 69 | if (Headers.class.equals(type)) { |
@@ -171,6 +171,27 @@ public Exception requestFail(@NonNull HttpRequest<?> httpRequest, @NonNull Excep |
171 | 171 | return new HttpException(e.getMessage(), e); |
172 | 172 | } |
173 | 173 |
|
| 174 | + @NonNull |
| 175 | + @Override |
| 176 | + public Exception downloadFail(@NonNull HttpRequest<?> httpRequest, @NonNull Exception e) { |
| 177 | + if (e instanceof ResponseException) { |
| 178 | + ResponseException responseException = ((ResponseException) e); |
| 179 | + Response response = responseException.getResponse(); |
| 180 | + responseException.setMessage(String.format(mApplication.getString(R.string.http_response_error), |
| 181 | + response.code(), response.message())); |
| 182 | + return responseException; |
| 183 | + } else if (e instanceof NullBodyException) { |
| 184 | + NullBodyException nullBodyException = ((NullBodyException) e); |
| 185 | + nullBodyException.setMessage(mApplication.getString(R.string.http_response_null_body)); |
| 186 | + return nullBodyException; |
| 187 | + } else if (e instanceof FileMD5Exception) { |
| 188 | + FileMD5Exception fileMd5Exception = ((FileMD5Exception) e); |
| 189 | + fileMd5Exception.setMessage(mApplication.getString(R.string.http_response_md5_error)); |
| 190 | + return fileMd5Exception; |
| 191 | + } |
| 192 | + return requestFail(httpRequest, e); |
| 193 | + } |
| 194 | + |
174 | 195 | @Nullable |
175 | 196 | @Override |
176 | 197 | public Object readCache(@NonNull HttpRequest<?> httpRequest, @NonNull Type type, long cacheTime) { |
|
0 commit comments