diff --git a/android/src/main/java/io/invertase/googleads/ReactNativeGoogleAdsCommon.java b/android/src/main/java/io/invertase/googleads/ReactNativeGoogleAdsCommon.java index efb7f891..b8465568 100644 --- a/android/src/main/java/io/invertase/googleads/ReactNativeGoogleAdsCommon.java +++ b/android/src/main/java/io/invertase/googleads/ReactNativeGoogleAdsCommon.java @@ -28,6 +28,7 @@ import com.facebook.react.bridge.WritableMap; import com.facebook.react.views.view.ReactViewGroup; import com.google.ads.mediation.admob.AdMobAdapter; +import com.google.android.gms.ads.AdError; import com.google.android.gms.ads.AdRequest; import com.google.android.gms.ads.AdSize; import io.invertase.googleads.common.ReactNativeEventEmitter; @@ -216,47 +217,34 @@ public static void sendAdEvent( emitter.sendEvent(new ReactNativeGoogleAdsEvent(event, requestId, adUnitId, eventBody)); } - public static String[] getCodeAndMessageFromAdErrorCode(int errorCode) { + public static String[] getCodeAndMessageFromAdError(AdError adError) { String code = "unknown"; - String message = "An unknown error occurred."; + String message = adError.getMessage(); - switch (errorCode) { + switch (adError.getCode()) { case AdRequest.ERROR_CODE_APP_ID_MISSING: code = "app-id-missing"; - message = "The ad request was not made due to a missing app ID."; break; case AdRequest.ERROR_CODE_INTERNAL_ERROR: code = "internal-error"; - message = - "Something happened internally; for instance, an invalid response was received from the" - + " ad server."; break; case AdRequest.ERROR_CODE_INVALID_AD_STRING: code = "invalid-ad-string"; - message = "The ad string is invalid."; break; case AdRequest.ERROR_CODE_INVALID_REQUEST: code = "invalid-request"; - message = "The ad request was invalid; for instance, the ad unit ID was incorrect."; break; case AdRequest.ERROR_CODE_MEDIATION_NO_FILL: code = "mediation-no-fill"; - message = "The mediation adapter did not fill the ad request."; break; case AdRequest.ERROR_CODE_NETWORK_ERROR: code = "network-error"; - message = "The ad request was unsuccessful due to network connectivity."; break; case AdRequest.ERROR_CODE_NO_FILL: code = "no-fill"; - message = - "The ad request was successful, but no ad was returned due to lack of ad inventory."; break; case AdRequest.ERROR_CODE_REQUEST_ID_MISMATCH: code = "request-id-mismatch"; - message = - "The AdInfo object inside the ad request has mismatching request IDs or the request ID" - + " in the ad string is not found."; break; } diff --git a/android/src/main/java/io/invertase/googleads/ReactNativeGoogleAdsInterstitialModule.java b/android/src/main/java/io/invertase/googleads/ReactNativeGoogleAdsInterstitialModule.java index de934e25..284e064d 100644 --- a/android/src/main/java/io/invertase/googleads/ReactNativeGoogleAdsInterstitialModule.java +++ b/android/src/main/java/io/invertase/googleads/ReactNativeGoogleAdsInterstitialModule.java @@ -17,7 +17,7 @@ * */ -import static io.invertase.googleads.ReactNativeGoogleAdsCommon.getCodeAndMessageFromAdErrorCode; +import static io.invertase.googleads.ReactNativeGoogleAdsCommon.getCodeAndMessageFromAdError; import static io.invertase.googleads.ReactNativeGoogleAdsCommon.sendAdEvent; import static io.invertase.googleads.ReactNativeGoogleAdsEvent.GOOGLE_ADS_EVENT_CLICKED; import static io.invertase.googleads.ReactNativeGoogleAdsEvent.GOOGLE_ADS_EVENT_CLOSED; @@ -105,8 +105,7 @@ public void onAdShowedFullScreenContent() { @Override public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) { WritableMap error = Arguments.createMap(); - int errorCode = loadAdError.getCode(); - String[] codeAndMessage = getCodeAndMessageFromAdErrorCode(errorCode); + String[] codeAndMessage = getCodeAndMessageFromAdError(loadAdError); error.putString("code", codeAndMessage[0]); error.putString("message", codeAndMessage[1]); sendInterstitialEvent(GOOGLE_ADS_EVENT_ERROR, requestId, adUnitId, error); diff --git a/android/src/main/java/io/invertase/googleads/ReactNativeGoogleAdsRewardedModule.java b/android/src/main/java/io/invertase/googleads/ReactNativeGoogleAdsRewardedModule.java index 2e9d1a12..53fa7094 100644 --- a/android/src/main/java/io/invertase/googleads/ReactNativeGoogleAdsRewardedModule.java +++ b/android/src/main/java/io/invertase/googleads/ReactNativeGoogleAdsRewardedModule.java @@ -1,6 +1,6 @@ package io.invertase.googleads; -import static io.invertase.googleads.ReactNativeGoogleAdsCommon.getCodeAndMessageFromAdErrorCode; +import static io.invertase.googleads.ReactNativeGoogleAdsCommon.getCodeAndMessageFromAdError; import static io.invertase.googleads.ReactNativeGoogleAdsCommon.sendAdEvent; import static io.invertase.googleads.ReactNativeGoogleAdsEvent.GOOGLE_ADS_EVENT_CLOSED; import static io.invertase.googleads.ReactNativeGoogleAdsEvent.GOOGLE_ADS_EVENT_ERROR; @@ -71,8 +71,7 @@ public void rewardedLoad(int requestId, String adUnitId, ReadableMap adRequestOp @Override public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) { WritableMap error = Arguments.createMap(); - int errorCode = loadAdError.getCode(); - String[] codeAndMessage = getCodeAndMessageFromAdErrorCode(errorCode); + String[] codeAndMessage = getCodeAndMessageFromAdError(loadAdError); error.putString("code", codeAndMessage[0]); error.putString("message", codeAndMessage[1]); sendRewardedEvent(GOOGLE_ADS_EVENT_ERROR, requestId, adUnitId, error, null); diff --git a/ios/RNGoogleAds/RNGoogleAdsCommon.m b/ios/RNGoogleAds/RNGoogleAdsCommon.m index 0fa0e89d..792886a1 100644 --- a/ios/RNGoogleAds/RNGoogleAdsCommon.m +++ b/ios/RNGoogleAds/RNGoogleAdsCommon.m @@ -87,55 +87,38 @@ + (GADRequest *)buildAdRequest:(NSDictionary *)adRequestOptions { + (NSDictionary *)getCodeAndMessageFromAdError:(NSError *)error { NSString *code = @"unknown"; - NSString *message = @"An unknown error occurred."; + NSString *message = [error localizedDescription]; if (error.code == GADErrorInvalidRequest) { code = @"invalid-request"; - message = @"The ad request was invalid; for instance, the ad unit ID was incorrect."; } else if (error.code == GADErrorNoFill) { code = @"no-fill"; - message = @"The ad request was successful, but no ad was returned due to lack of ad inventory."; } else if (error.code == GADErrorNetworkError) { code = @"network-error"; - message = @"The ad request was unsuccessful due to network connectivity."; } else if (error.code == GADErrorServerError) { code = @"server-error"; - message = @"The ad server experienced a failure processing the request."; } else if (error.code == GADErrorOSVersionTooLow) { code = @"os-version-too-low"; - message = @"The current device’s OS is below the minimum required version."; } else if (error.code == GADErrorTimeout) { code = @"timeout"; - message = @"The request was unable to be loaded before being timed out."; } else if (error.code == GADErrorMediationDataError) { code = @"mediation-data-error"; - message = @"The mediation response was invalid."; } else if (error.code == GADErrorMediationAdapterError) { code = @"mediation-adapter-error"; - message = @"Error finding or creating a mediation ad network adapter."; } else if (error.code == GADErrorMediationInvalidAdSize) { code = @"mediation-invalid-ad-size"; - message = @"Attempting to pass an invalid ad size to an adapter."; } else if (error.code == GADErrorInternalError) { code = @"internal-error"; - message = @"Something happened internally; for instance, an invalid response was received from " - @"the ad server."; } else if (error.code == GADErrorInvalidArgument) { code = @"invalid-argument"; - message = @"Invalid argument error."; } else if (error.code == GADErrorReceivedInvalidResponse) { code = @"received-invalid-response"; - message = @"Received invalid response."; } else if (error.code == GADErrorMediationNoFill) { code = @"mediation-no-fill"; - message = @"A mediation ad network adapter received an ad request, but did not fill. The " - @"adapter’s error is included as an underlyingError."; } else if (error.code == GADErrorAdAlreadyUsed) { code = @"ad-already-used"; - message = @"Will not send request because the ad object has already been used."; } else if (error.code == GADErrorApplicationIdentifierMissing) { code = @"application-identifier-missing"; - message = @"Will not send request because the application identifier is missing."; } return @{