Skip to content

Commit

Permalink
Fix 404 error handling (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy-mitchell authored Feb 27, 2024
1 parent aa590a4 commit f8e0a28
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default async function npmUser(username) {
twitter: $sidebar.find('a[href^="https://twitter.com/"]').text().slice(1) || undefined,
};
} catch (error) {
if (error.statusCode === 404) {
if (error.response.status === 404) {
error.message = 'User doesn\'t exist';
}

Expand Down
7 changes: 7 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,10 @@ test('user: tj', async t => {

t.regex(user.avatar, avatarRegex);
});

test('handles non-existent user', async t => {
await t.throwsAsync(
npmUser('sindresorhus123'),
{message: 'User doesn\'t exist'},
);
});

0 comments on commit f8e0a28

Please sign in to comment.