Error Handling
When BlueStack SDK encounters an error, it fires the failed callback delegate with an AdError object.
Error codes
BlueStack SDK reports with following error codes:
| Error Code | Constant | Description |
|---|---|---|
| 0 | AdErrorWrongPlacement | Wrong placement Id was provided when loading the ad |
| -1000 | AdErrorAdServer | An ad server error occurred while loading the ad |
| -1001 | AdErrorDataAdServer | The ad response contains invalid or malformed data |
| -1002 | AdErrorNoInternet | No internet connection is available to complete the ad request |
| -999 | AdErrorSDKUninitialized | The ad was requested before the SDK finished initialization |
| -998 | AdErrorCappedRequest | The ad request has been capped |
| -997 | AdErrorLockedPlacement | The placement is locked or already in use by another resource |
| -996 | AdErrorBusyFactory | Multiple ads are being loaded concurrently using the same placement Id |
| -995 | AdErrorBusy | The SDK is busy loading one or more ads |
| -994 | AdErrorUnallowedBackgroundRequest | The SDK cannot send a request while the application is in the background |
| -993 | AdErrorNoAds | No ad fill is available for the given placement Id |
| -992 | AdErrorInterstitialCooldown | The time between the last interstitial dismiss and the new interstitial request is less than 5 seconds |
| -991 | AdErrorAlreadyShownInterstitial | Another interstitial ad is already being displayed |
| -990 | AdErrorAlreadyShownAppOpen | An app open ad is already being displayed |
| -989 | AdErrorRequestTimedOut | The ad request timed out before a response was received |
| -988 | AdErrorMissingViewController | No root view controller was provided and the SDK could not find the top-most view controller |
| -987 | AdErrorUnableToDisplayAd | The full-screen ad was requested to show before it finished loading |
| -986 | AdErrorAdExpired | The ad has expired and can no longer be displayed |
| -985 | AdErrorNoAdapterFoundForPlacement | No mediation adapter was found for the given placement |
| -984 | AdErrorAdapterClassNotFound | The mediation adapter class could not be found or loaded |
| -983 | AdErrorInternal | An internal SDK error occurred |
Handling the Error
Following is an example of handling errors for an Banner Ad.
- Objective C
- Swift
- (void)bannerView:(BLSBannerView * _Nonnull)bannerView didFailedToLoadWithError:(NSError * _Nonnull)error {
switch (error.code) {
case AdErrorWrongPlacement:
NSLog(@"Wrong placement Id. %@", error.localizedDescription);
break;
case AdErrorSDKUninitialized:
NSLog(@"BlueStack SDK is not initialized. %@", error.localizedDescription);
break;
default:
NSLog(@"Unhandled error");
break;
}
}
func onFailedToLoad(_ bannerView: BlueStackSDK.BannerView, _ error: any Error) {
guard let error = error as? AdError, let errorCode = AdErrorCode(rawValue: error.code) else { return }
switch errorCode {
case .wrongPlacement:
print("Wrong placement Id. \(error.localizedDescription)")
break
case .sdkUninitialized:
print("BlueStack SDK is not initialized. \(error.localizedDescription)")
break
default:
print("Unhandled error. \(error.localizedDescription)")
break
}
}