Skip to content

Commit

Permalink
clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
khanh1902 committed Jun 8, 2024
1 parent b5324c1 commit 39b3cee
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions services/translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@ const translate = async (text, fromLang = 'auto', toLang = 'en') => {
)}`,
};

console.log(config);
console.log('[translate] - ' + JSON.stringify(config));

const { data } = await axios(config);

if (!data) {
throw new Error('Can not translate text');
}

console.log(`[freeTranslate] Translated: ${JSON.stringify(data)}`);
console.log(`Translated: ${fromLang} -> ${toLang} | ${text} -> ${data[0][0][0]}`);

return data[0][0][0];
} catch (error) {
console.log('[freeTranslate] err:', error.message);
console.log('Translate filed - ', error.message);
console.log(error.response && error.response.data);
console.error(error.stack);
return text;
Expand Down

0 comments on commit 39b3cee

Please sign in to comment.