Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: smarter error logging #50

Merged
merged 9 commits into from
Dec 29, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand Down
19 changes: 1 addition & 18 deletions ios/RNGoogleAds/RNGoogleAdsCommon.m
Original file line number Diff line number Diff line change
Expand Up @@ -87,55 +87,38 @@ + (GADRequest *)buildAdRequest:(NSDictionary *)adRequestOptions {

+ (NSDictionary *)getCodeAndMessageFromAdError:(NSError *)error {
dylancom marked this conversation as resolved.
Show resolved Hide resolved
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 @{
Expand Down