Skip to content

Commit d1fbf82

Browse files
authored
Merge pull request #423 from apify/fix-try-catch
fix: Try catch block
2 parents eb3519a + 146558c commit d1fbf82

File tree

4 files changed

+24
-50
lines changed

4 files changed

+24
-50
lines changed

content/academy/apify_platform/publishing_actors_on_apify_store.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ paths:
88

99
# [](#publishing-actors-on-apify-store) Publishing actors on Apify Store
1010

11-
[Apify Store](https://apify.com/store) is home to hundreds of public actors available to the Apify community. Anyone is welcome to publish actors in the store, and you can even [monetize your actors](https://get.apify.com/monetize-your-code) by renting them to users of the platform.
11+
[Apify Store](https://apify.com/store) is home to hundreds of public actors available to the Apify community. Anyone is welcome to publish actors in the store, and you can even [monetize your actors](https://get.apify.com/monetize-your-code) by renting them to users of the platform.
1212

13-
In this section, we will go over the practical steps you should take before publishing your actor. You will learn:
13+
In this section, we will go over the practical steps you should take before publishing your actor. You will learn:
1414

1515
1. How to publish an actor.
1616
2. How to monetize your actor by renting it to other platform users.

content/academy/apify_platform/publishing_actors_on_apify_store/monetizing_your_actor.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ Your paid actors’ earnings are directly related to the amount of paying users
4444

4545
Getting new users can be an art in itself, but there are **two simple steps** you can take to ensure your actor is getting the attention it deserves.
4646

47-
1. **SEO-optimized description and README**
47+
1. **SEO-optimized description and README**
4848

4949
Search engine optimization (SEO) is the process of improving the quality and quantity of traffic from search engines to your actor’s page.
5050

5151
In short, SEO-optimized texts improve the likelihood that potential customers will find your actor when searching for similar tools on the web.
5252

5353
This can be a daunting task to take on your own, so we prepared an in-depth [SEO guide](https://docs.apify.com/actors/publishing/seo-and-promotion) to help you **fine-tune your actor’s title, description, and Readme.**
5454

55-
2. **Promoting your actor**
55+
2. **Promoting your actor**
5656

5757
Promoting your actor on the right channels can be the deciding factor in successfully attracting users.
5858

content/academy/expert_scraping_with_apify/solutions/using_api_and_client.md

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,14 @@ const withClient = async () => {
5656

5757
const dataset = client.run(id).dataset();
5858

59-
try {
60-
const items = await dataset.downloadItems('csv', {
61-
limit: maxItems,
62-
fields,
63-
});
59+
const items = await dataset.downloadItems('csv', {
60+
limit: maxItems,
61+
fields,
62+
});
6463

65-
// If the content type is anything other than JSON, it must
66-
// be specified within the third options parameter
67-
return Apify.setValue('OUTPUT', items, { contentType: 'text/csv' });
68-
} catch (error) {
69-
throw new Error(error?.message);
70-
}
64+
// If the content type is anything other than JSON, it must
65+
// be specified within the third options parameter
66+
return Apify.setValue('OUTPUT', items, { contentType: 'text/csv' });
7167
};
7268
```
7369

@@ -113,13 +109,9 @@ const withAPI = async () => {
113109
token: process.env.APIFY_TOKEN,
114110
});
115111

116-
try {
117-
const { data } = await axios.post(url.toString());
112+
const { data } = await axios.post(url.toString());
118113

119-
return Apify.setValue('OUTPUT', data, { contentType: 'text/csv' });
120-
} catch (error) {
121-
throw new Error(error?.message);
122-
}
114+
return Apify.setValue('OUTPUT', data, { contentType: 'text/csv' });
123115
};
124116
```
125117

@@ -194,16 +186,12 @@ Apify.main(async () => {
194186

195187
const dataset = client.run(id).dataset();
196188

197-
try {
198-
const items = await dataset.downloadItems('csv', {
199-
limit: maxItems,
200-
fields,
201-
});
189+
const items = await dataset.downloadItems('csv', {
190+
limit: maxItems,
191+
fields,
192+
});
202193

203-
return Apify.setValue('OUTPUT', items, { contentType: 'text/csv' });
204-
} catch (error) {
205-
throw new Error(error?.message);
206-
}
194+
return Apify.setValue('OUTPUT', items, { contentType: 'text/csv' });
207195
};
208196

209197
const withAPI = async () => {
@@ -218,13 +206,9 @@ Apify.main(async () => {
218206
token: process.env.APIFY_TOKEN,
219207
});
220208

221-
try {
222-
const { data } = await axios.post(url.toString());
209+
const { data } = await axios.post(url.toString());
223210

224-
return Apify.setValue('OUTPUT', data, { contentType: 'text/csv' });
225-
} catch (error) {
226-
throw new Error(error?.message);
227-
}
211+
return Apify.setValue('OUTPUT', data, { contentType: 'text/csv' });
228212
};
229213

230214
if (useClient) await withClient();

content/academy/puppeteer_playwright/page/page_methods.md

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,8 @@ console.log(title);
3434
The `page.screenshot()` function will return a buffer which can be written to the filesystem as an image:
3535

3636
```JavaScript
37-
import * as fs from 'fs/promises';
38-
// ...
39-
40-
// Take the screenshot
41-
const screenshot = await page.screenshot();
42-
43-
// Write the image to the filesystem
44-
await fs.writeFile('screenshot.png', screenshot);
37+
// Take the screenshot and write it to the filesystem
38+
await page.screenshot({ path: 'screenshot.png' });
4539
```
4640

4741
> The image will by default be **.png**. To change the image to **.jpeg** type, set the (optional) `type` option to **jpeg**.
@@ -53,7 +47,6 @@ Here's our final code which extracts the page's title, takes a screenshot and sa
5347
```marked-tabs
5448
<marked-tab header="Playwright" lang="javascript">
5549
import { chromium } from 'playwright';
56-
import * as fs from 'fs/promises';
5750
5851
const browser = await chromium.launch({ headless: false });
5952
@@ -77,14 +70,12 @@ const title = await page.title();
7770
console.log(title);
7871
7972
// Take a screenshot and write it to the filesystem
80-
const screenshot = await page.screenshot();
81-
await fs.writeFile('screenshot.png', screenshot);
73+
await page.screenshot({ path: 'screenshot.png' });
8274
8375
await browser.close();
8476
</marked-tab>
8577
<marked-tab header="Puppeteer" lang="javascript">
8678
import puppeteer from 'puppeteer';
87-
import * as fs from 'fs/promises';
8879
8980
const browser = await puppeteer.launch({ headless: false });
9081
@@ -109,8 +100,7 @@ const title = await page.title();
109100
console.log(title);
110101
111102
// Take a screenshot and write it to the filesystem
112-
const screenshot = await page.screenshot();
113-
await fs.writeFile('screenshot.png', screenshot);
103+
await page.screenshot({ path: 'screenshot.png' });
114104
115105
await browser.close();
116106
</marked-tab>

0 commit comments

Comments
 (0)