Skip to content

Commit ed14203

Browse files
benuboisadampash
authored andcommitted
fix: return early if creating the resource failed. (#285)
1 parent 52dfdda commit ed14203

3 files changed

Lines changed: 44 additions & 3 deletions

File tree

fixtures/nock/mercury-test.js

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/mercury.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ const Mercury = {
3232

3333
const $ = await Resource.create(url, html, parsedUrl);
3434

35-
const Extractor = getExtractor(url, parsedUrl, $);
36-
// console.log(`Using extractor for ${Extractor.domain}`);
37-
3835
// If we found an error creating the resource, return that error
3936
if ($.failed) {
4037
return $;
4138
}
4239

40+
const Extractor = getExtractor(url, parsedUrl, $);
41+
// console.log(`Using extractor for ${Extractor.domain}`);
42+
4343
// if html still has not been set (i.e., url passed to Mercury.parse),
4444
// set html from the response of Resource.create
4545
if (!html) {

src/mercury.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ describe('Mercury', () => {
3333
assert.equal(result.content.indexOf('score="') === -1, true);
3434
});
3535

36+
it('returns an error on non-2xx responses', async () => {
37+
const error = await Mercury.parse(
38+
'https://www.thekitchn.com/instant-pot-chicken-pesto-pasta-eating-instantly-267141'
39+
);
40+
41+
assert.equal(error, Errors.badUrl);
42+
});
43+
3644
it('does blogger', async () => {
3745
const result = await Mercury.parse(
3846
'https://googleblog.blogspot.com/2016/08/onhub-turns-one-today.html'

0 commit comments

Comments
 (0)