Skip to content

Commit

Permalink
fix: typescript error
Browse files Browse the repository at this point in the history
Also, prevent an error if the server respond with a different status code,
other than 200
  • Loading branch information
gil0mendes committed Sep 26, 2021
1 parent 88c03e5 commit dcc57b7
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion component/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const Q_COUNT = ".loveCount";
* @param url target url to get number of loves to
* @returns number of loves the page has
*/
async function getLoves(url?: string): Promise<number> {
async function getLoves(url: string | null): Promise<number> {
const baseUrl = `${API_URL}/page-loves`;
const targetUrl = !!url ? `${baseUrl}?url=${url}` : baseUrl;

Expand All @@ -24,6 +24,10 @@ async function getLoves(url?: string): Promise<number> {
},
});

if (response.status !== 200) {
throw "Invalid request";
}

return Number(await response.text());
}

Expand Down

0 comments on commit dcc57b7

Please sign in to comment.