@@ -69,17 +69,20 @@ public class BaseImageDownloader implements ImageDownloader {
69
69
protected final Context context ;
70
70
protected final int connectTimeout ;
71
71
protected final int readTimeout ;
72
+ /**
73
+ * Whether read stream if server returned non-200 response
74
+ */
75
+ protected final boolean readOnError ;
72
76
73
77
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 );
77
79
}
78
80
79
- public BaseImageDownloader (Context context , int connectTimeout , int readTimeout ) {
81
+ public BaseImageDownloader (Context context , int connectTimeout , int readTimeout , boolean readOnError ) {
80
82
this .context = context .getApplicationContext ();
81
83
this .connectTimeout = connectTimeout ;
82
84
this .readTimeout = readTimeout ;
85
+ this .readOnError = readOnError ;
83
86
}
84
87
85
88
@ Override
@@ -123,6 +126,9 @@ protected InputStream getStreamFromNetwork(String imageUri, Object extra) throws
123
126
124
127
InputStream imageStream ;
125
128
try {
129
+ if (conn .getResponseCode () != 200 && !readOnError ) {
130
+ throw new IOException ("Unable to retrieve image. Response code: " + conn .getResponseCode ());
131
+ }
126
132
imageStream = conn .getInputStream ();
127
133
} catch (IOException e ) {
128
134
// Read all data to allow reuse connection (http://bit.ly/1ad35PY)
0 commit comments