Skip to content

Commit

Permalink
Return a message for missing ranks (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
hkamran80 authored Jun 15, 2024
1 parent 4054c17 commit 18032f8
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/tests/SimilarWeb.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default async function(domain, env) {
}
});

if (res.status === 404) throw new Error(`${domain} doesn't have a Similarweb rank.`)
if (!res.ok) throw new Error('Unable to fetch website rank');

const json = await res.json();
Expand All @@ -23,12 +24,12 @@ export default async function(domain, env) {
if(json.meta.status !== 'Success') return 1;

if (!Object.keys(json).includes('similar_rank'))
throw new Error(`${domain} doesn't have a SimilarWeb rank.`);
throw new Error(`${domain} doesn't have a Similarweb rank.`);

const { rank } = json.similar_rank;

if (rank > env.SIMILARWEB_RANK_LIMIT)
throw new Error(`${domain} SimilarWeb rank ${rank.toLocaleString()} exceeds the limit of ${env.SIMILARWEB_RANK_LIMIT.toLocaleString()}.`);
throw new Error(`${domain} Similarweb rank ${rank.toLocaleString()} exceeds the limit of ${env.SIMILARWEB_RANK_LIMIT.toLocaleString()}.`);

logger.addMessage(test, `${domain} ranked ${rank.toLocaleString()}`);

Expand Down

0 comments on commit 18032f8

Please sign in to comment.