From 92647294e2605eb2db61792be12ba559658bf8f2 Mon Sep 17 00:00:00 2001 From: Jay Date: Sun, 28 Nov 2021 23:10:22 +0900 Subject: [PATCH] docs: update AdError doc --- docs/docs/api/classes/AdError.mdx | 18 +++++++++++++++++ docs/docs/api/classes/AppOpenAd.mdx | 18 ++++++++--------- docs/docs/api/classes/FullScreenAd.mdx | 20 +++++++++---------- docs/docs/api/hooks/useAppOpenAd.mdx | 4 ++-- docs/docs/api/hooks/useFullScreenAd.mdx | 4 ++-- .../FullScreenAdExamples/HookApiExample.tsx | 13 ++++++++---- src/AdError.ts | 6 ++++++ 7 files changed, 56 insertions(+), 27 deletions(-) create mode 100644 docs/docs/api/classes/AdError.mdx diff --git a/docs/docs/api/classes/AdError.mdx b/docs/docs/api/classes/AdError.mdx new file mode 100644 index 0000000..2ac1dbe --- /dev/null +++ b/docs/docs/api/classes/AdError.mdx @@ -0,0 +1,18 @@ +Error class containing the details of the error. + +Refer to [common error message descriptions](https://support.google.com/admob/answer/9905175) to find cause of the error. + +## Properties + +### `code` + +The error code provided by Google Mobile Ads SDK. + +Possible codes and descriptions: + +- [Android](https://developers.google.com/android/reference/com/google/android/gms/ads/AdRequest#constant-summary) +- [iOS](https://developers.google.com/admob/ios/api/reference/Enums/GADErrorCode) + +### `message` + +The error description message. diff --git a/docs/docs/api/classes/AppOpenAd.mdx b/docs/docs/api/classes/AppOpenAd.mdx index ed49fb1..fbc5c53 100644 --- a/docs/docs/api/classes/AppOpenAd.mdx +++ b/docs/docs/api/classes/AppOpenAd.mdx @@ -68,7 +68,7 @@ Generally you don't need to call this function because ad is loaded automaticall **Returns** -`Promise` that waits for ad load. When error is occured while loading ad, the Promise will reject with `Error` object. +`Promise` that waits for ad load. When error is occured while loading ad, the Promise will reject with `AdError` object. ### show() @@ -84,7 +84,7 @@ You don't need to call this function if you set `showOnAppForeground` option to **Returns** -`Promise` that waits for ad present. When error is occurred while presenting ad, the Promise will reject with `Error` object. +`Promise` that waits for ad present. When error is occurred while presenting ad, the Promise will reject with `AdError` object. ### addEventListener() @@ -98,13 +98,13 @@ Adds an event handler for an ad event. `event` : Event name. Supported events: -| Event Name | Description | -| ----------------- | ------------------------------------------------------------------------------------------------------ | -| adLoaded | Fires when the ad has finished loading. | -| adFailedToLoad | Fires when the ad has failed to load. The argument to the event handler is `Error` object. | -| adPresented | Fires when the ad is presented to user. | -| adFailedToPresent | Fires when an error occurred while presenting ad. The argument to the event handler is `Error` object. | -| adDismissed | Fires when the ad is dismissed. | +| Event Name | Description | +| ----------------- | -------------------------------------------------------------------------------------------------------- | +| adLoaded | Fires when the ad has finished loading. | +| adFailedToLoad | Fires when the ad has failed to load. The argument to the event handler is `AdError` object. | +| adPresented | Fires when the ad is presented to user. | +| adFailedToPresent | Fires when an error occurred while presenting ad. The argument to the event handler is `AdError` object. | +| adDismissed | Fires when the ad is dismissed. | `handler` : An event handler. diff --git a/docs/docs/api/classes/FullScreenAd.mdx b/docs/docs/api/classes/FullScreenAd.mdx index a6bdbfc..522571c 100644 --- a/docs/docs/api/classes/FullScreenAd.mdx +++ b/docs/docs/api/classes/FullScreenAd.mdx @@ -50,7 +50,7 @@ Loads new Ad. **Returns** -`Promise` that waits for ad load. When error is occured while loading ad, the Promise will reject with `Error` object. +`Promise` that waits for ad load. When error is occured while loading ad, the Promise will reject with `AdError` object. ### show() @@ -64,7 +64,7 @@ Ad must be loaded before calling this function. **Returns** -`Promise` that waits for ad present. When error is occurred while presenting ad, the Promise will reject with `Error` object. +`Promise` that waits for ad present. When error is occurred while presenting ad, the Promise will reject with `AdError` object. ### addEventListener() @@ -78,14 +78,14 @@ Adds an event handler for an ad event. `event` : Event name. Supported events: -| Event Name | Description | -| ----------------- | ------------------------------------------------------------------------------------------------------ | -| adLoaded | Fires when the ad has finished loading. | -| adFailedToLoad | Fires when the ad has failed to load. The argument to the event handler is `Error` object. | -| adPresented | Fires when the ad is presented to user. | -| adFailedToPresent | Fires when an error occurred while presenting ad. The argument to the event handler is `Error` object. | -| adDismissed | Fires when the ad is dismissed. | -| rewarded | Fires when user earned reward. The argument to the event handler is `Reward` object. | +| Event Name | Description | +| ----------------- | -------------------------------------------------------------------------------------------------------- | +| adLoaded | Fires when the ad has finished loading. | +| adFailedToLoad | Fires when the ad has failed to load. The argument to the event handler is `AdError` object. | +| adPresented | Fires when the ad is presented to user. | +| adFailedToPresent | Fires when an error occurred while presenting ad. The argument to the event handler is `AdError` object. | +| adDismissed | Fires when the ad is dismissed. | +| rewarded | Fires when user earned reward. The argument to the event handler is `Reward` object. | `handler` : An event handler. diff --git a/docs/docs/api/hooks/useAppOpenAd.mdx b/docs/docs/api/hooks/useAppOpenAd.mdx index a358d4c..09860ca 100644 --- a/docs/docs/api/hooks/useAppOpenAd.mdx +++ b/docs/docs/api/hooks/useAppOpenAd.mdx @@ -14,8 +14,8 @@ Properties: | adPresented | boolean | Whether your ad is presented to user. The value remains `true` until **new ad is requested**. | | adDismissed | boolean | Whether your ad is dismissed. The value remains `true` until new ad is requested. | | adShowing | boolean | Whether your ad is showing. The value is equal with `adPresented && !adDismissed`. | -| adLoadError | Error | Error during ad load. | -| adPresentError | Error | Error during ad present. | +| adLoadError | AdError | `AdError` object throwed during ad load. | +| adPresentError | AdError | `AdError` object throwed during ad present. | | load | Function | Loads new ad. | | show | Function | Shows loaded ad. Ad must be loaded prior to this call. | diff --git a/docs/docs/api/hooks/useFullScreenAd.mdx b/docs/docs/api/hooks/useFullScreenAd.mdx index d3b1198..bdb51d0 100644 --- a/docs/docs/api/hooks/useFullScreenAd.mdx +++ b/docs/docs/api/hooks/useFullScreenAd.mdx @@ -42,8 +42,8 @@ Properties: | adPresented | boolean | Whether your ad is presented to user. The value remains `true` until **new ad is requested**. | | adDismissed | boolean | Whether your ad is dismissed. The value remains `true` until new ad is requested. | | adShowing | boolean | Whether your ad is showing. The value is equal with `adPresented && !adDismissed`. | -| adLoadError | Error \| undefined | `Error` object throwed during ad load. | -| adPresentError | Error \| undefined | `Error` object throwed during ad present. | +| adLoadError | AdError \| undefined | `AdError` object throwed during ad load. | +| adPresentError | AdError \| undefined | `AdError` object throwed during ad present. | | reward | [Reward](#) \| undefined | Reward earned by user. The value is `undefined` until user earns reward. Available only in RewardedAd or RewardedInterstitialAd. | | load | Function | Loads new ad. | | show | Function | Shows loaded ad. Ad must be loaded prior to this call. | diff --git a/example/src/examples/FullScreenAdExamples/HookApiExample.tsx b/example/src/examples/FullScreenAdExamples/HookApiExample.tsx index b88af56..c51777d 100644 --- a/example/src/examples/FullScreenAdExamples/HookApiExample.tsx +++ b/example/src/examples/FullScreenAdExamples/HookApiExample.tsx @@ -20,10 +20,8 @@ const hookOptions: FullScreenAdOptions = { const HookApiExample = () => { const [modalVisible, setModalVisible] = useState(false); - const { adLoaded, adDismissed, reward, show } = useRewardedInterstitialAd( - TestIds.REWARDED_INTERSTITIAL, - hookOptions - ); + const { adLoaded, adDismissed, reward, show, adLoadError } = + useRewardedInterstitialAd(TestIds.REWARDED_INTERSTITIAL, hookOptions); const navigation = useNavigation>(); const navigateToSecondScreen = useCallback( @@ -45,6 +43,13 @@ const HookApiExample = () => { } }, [reward]); + useEffect(() => { + if (adLoadError) { + const { code, message } = adLoadError; + console.log(`Ad failed to load with code ${code} - ${message}`); + } + }, [adLoadError]); + return ( <> diff --git a/src/AdError.ts b/src/AdError.ts index bc07c8d..5c7cddf 100644 --- a/src/AdError.ts +++ b/src/AdError.ts @@ -1,5 +1,11 @@ export default class AdError extends Error { name = 'AdError'; + /** + * AdError + * @param message - The error description message. + * @param code - The error code. + * @link https://support.google.com/admob/answer/9905175 + */ constructor(public readonly message: string, public readonly code?: number) { super(); }