Skip to content
This repository has been archived by the owner on Apr 27, 2022. It is now read-only.

Commit

Permalink
docs: update AdError doc
Browse files Browse the repository at this point in the history
  • Loading branch information
wjaykim committed Nov 28, 2021
1 parent c92128e commit 9264729
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 27 deletions.
18 changes: 18 additions & 0 deletions 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.
18 changes: 9 additions & 9 deletions docs/docs/api/classes/AppOpenAd.mdx
Expand Up @@ -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()

Expand All @@ -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()

Expand All @@ -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.

Expand Down
20 changes: 10 additions & 10 deletions docs/docs/api/classes/FullScreenAd.mdx
Expand Up @@ -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()

Expand All @@ -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()

Expand All @@ -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.

Expand Down
4 changes: 2 additions & 2 deletions docs/docs/api/hooks/useAppOpenAd.mdx
Expand Up @@ -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. |

Expand Down
4 changes: 2 additions & 2 deletions docs/docs/api/hooks/useFullScreenAd.mdx
Expand Up @@ -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. |
Expand Down
13 changes: 9 additions & 4 deletions example/src/examples/FullScreenAdExamples/HookApiExample.tsx
Expand Up @@ -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<RootStackNavigationProps<'Examples'>>();

const navigateToSecondScreen = useCallback(
Expand All @@ -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 (
<>
<ExampleGroup title="Rewarded Interstitial">
Expand Down
6 changes: 6 additions & 0 deletions 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();
}
Expand Down

0 comments on commit 9264729

Please sign in to comment.