Skip to content

Commit 81c28ff

Browse files
Fixed error handling (team-plain#13)
* Fixed error handling * Simplify code * Lint
1 parent 54fef7d commit 81c28ff

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

.changeset/nine-eels-shake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@team-plain/cli": minor
3+
---
4+
5+
Fixed error handling

src/index.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,15 @@ function handleError(message, requestId = "–") {
3131

3232
async function indexUrl(url, labelTypeIds = []) {
3333
const client = getClient();
34-
35-
const res = await client.indexDocument({
34+
const res = client.indexDocument({
3635
url,
3736
labelTypeIds,
3837
});
39-
4038
if (res.isErr) {
4139
handleError(res.error.message, res.error.requestId);
40+
} else {
41+
console.log(`✅ Successfully indexed ${url}`);
4242
}
43-
44-
console.log(`✅ Successfully indexed ${url}`);
4543
}
4644

4745
program.name("plain").version(packageJson.version).description("Plain CLI");
@@ -74,15 +72,12 @@ program
7472
urls.push(...res.sites);
7573
} catch (e) {
7674
console.err(`Failed to fetch sitemap: ${e.message}`);
75+
process.exit(1);
7776
}
7877

7978
for (const url of urls) {
80-
const res = await indexUrl(url, labelTypeIds);
81-
if (res.isErr) {
82-
handleError(res.error.message, res.error.requestId);
83-
}
79+
await indexUrl(url, labelTypeIds);
8480
}
85-
8681
console.log(`Successfully indexed ${urls.length} urls`);
8782
});
8883

0 commit comments

Comments
 (0)