mopub/mopub-client — Issue #27: OnAdFailedListener not firing when adverts disabled
Author: zerofate
Created: 2012-01-06 15:34:57+00:00
State: open

as above. Its caused by the following:

AdView$LoadUrlTask

loadAdFromNetwork returns null for a variety of issues:

```java
if (mAdView == null || mAdView.isDestroyed()) {
Log.d("MoPub", "Error loading ad: AdView has already been GCed or destroyed.");
return null;
}

HttpResponse response = mHttpClient.execute(httpget);
HttpEntity entity = response.getEntity();

if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK ||
entity == null || entity.getContentLength() == 0) {
Log.d("MoPub", "Error loading ad: MoPub server returned invalid response.");
return null;
}

// Ensure that the ad type header is valid and not "clear".
Header atHeader = response.getFirstHeader("X-Adtype");
if (atHeader == null || atHeader.getValue().equals("clear")) {
Log.d("MoPub", "Error loading ad: MoPub server returned no ad.");
return null;
}
```
instead of logging and returning null it should throw an exception as later in onPostExecute mAdView.adDidFail(); is only fired if there was an exception.

```java
if (mException != null) {
Log.d("MoPub", "Exception caught while loading ad: " + mException);
mAdView.adDidFail();
} else if (result != null) {
result.execute();
result.cleanup();
}
```