Skip to content

Commit 9098964

Browse files
committed
Merge pull request nostra13#789 from mente/cache-error
Force to throw exception if server returned non-200 code
2 parents d25bb75 + c1b000c commit 9098964

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

library/src/com/nostra13/universalimageloader/core/download/BaseImageDownloader.java

+10-4
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,20 @@ public class BaseImageDownloader implements ImageDownloader {
6969
protected final Context context;
7070
protected final int connectTimeout;
7171
protected final int readTimeout;
72+
/**
73+
* Whether read stream if server returned non-200 response
74+
*/
75+
protected final boolean readOnError;
7276

7377
public BaseImageDownloader(Context context) {
74-
this.context = context.getApplicationContext();
75-
this.connectTimeout = DEFAULT_HTTP_CONNECT_TIMEOUT;
76-
this.readTimeout = DEFAULT_HTTP_READ_TIMEOUT;
78+
this(context.getApplicationContext(), DEFAULT_HTTP_CONNECT_TIMEOUT, DEFAULT_HTTP_READ_TIMEOUT, false);
7779
}
7880

79-
public BaseImageDownloader(Context context, int connectTimeout, int readTimeout) {
81+
public BaseImageDownloader(Context context, int connectTimeout, int readTimeout, boolean readOnError) {
8082
this.context = context.getApplicationContext();
8183
this.connectTimeout = connectTimeout;
8284
this.readTimeout = readTimeout;
85+
this.readOnError = readOnError;
8386
}
8487

8588
@Override
@@ -123,6 +126,9 @@ protected InputStream getStreamFromNetwork(String imageUri, Object extra) throws
123126

124127
InputStream imageStream;
125128
try {
129+
if (conn.getResponseCode() != 200 && !readOnError) {
130+
throw new IOException("Unable to retrieve image. Response code: " + conn.getResponseCode());
131+
}
126132
imageStream = conn.getInputStream();
127133
} catch (IOException e) {
128134
// Read all data to allow reuse connection (http://bit.ly/1ad35PY)

0 commit comments

Comments
 (0)