* Initial RESTful API

* RESTful API tests

* Scrapping error handling refactored

* Initial GraphQL API

* GraphQL API tests
This commit is contained in:
David
2021-03-28 23:17:47 +02:00
committed by GitHub
parent 7288e9ace7
commit 2938f780aa
15 changed files with 1873 additions and 671 deletions

View File

@@ -8,7 +8,6 @@ export async function googleScrape(
query: string
): Promise<{
translationRes?: string,
statusCode?: number,
errorMsg?: string
}> {
const parsed = replaceBoth("mapping", { source, target });
@@ -23,16 +22,11 @@ export async function googleScrape(
() => null
);
if (!res)
if (!res?.ok)
return {
errorMsg: "An error occurred while retrieving the translation"
}
if (!res.ok)
return {
statusCode: res.status
};
const html = await res.text();
const translationRes = cheerio.load(html)(".result-container").text().trim();