Skip to content

Commit c74a1ff

Browse files
committed
🐛 fix(plugin): throw better fetch failed msg #12
1 parent 7f635e9 commit c74a1ff

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

packages/plugin/src/gitmojiCode.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,24 @@ const filePath = join(__dirname, 'gitmojis.json');
77
if (!existsSync(filePath)) {
88
const url =
99
'https://raw.githubusercontent.com/carloscuesta/gitmoji/master/src/data/gitmojis.json';
10+
try {
11+
// eslint-disable-next-line global-require
12+
const result = require('child_process').execFileSync(
13+
'curl',
14+
['--silent', '-L', url],
15+
{
16+
encoding: 'utf8',
17+
maxBuffer: Infinity,
18+
},
19+
);
1020

11-
// eslint-disable-next-line global-require
12-
const result = require('child_process').execFileSync(
13-
'curl',
14-
['--silent', '-L', url],
15-
{
16-
encoding: 'utf8',
17-
maxBuffer: Infinity,
18-
},
19-
);
20-
21-
writeFileSync(filePath, result);
21+
writeFileSync(filePath, result);
22+
} catch (e) {
23+
throw Error(
24+
'Failed to fetch gitmoji JSON, please refer to https://github.com/arvinxx/gitmoji-commit-workflow/tree/master/packages/plugin#fetch-error for help.',
25+
);
26+
}
2227
}
23-
2428
// eslint-disable-next-line import/no-dynamic-require
2529
const { gitmojis } = require(filePath);
2630
const gitmojiCodes: string[] = gitmojis.map((gitmoji) => gitmoji.code);

0 commit comments

Comments
 (0)