I used a simple code to translate strings using @iamtraction/google-translate
const translate = require('@iamtraction/google-translate');
module.exports = function({ string, from, to }) {
return new Promise(resolve => {
run();
async function run() {
try {
const res = await translate(string, { from, to });
return resolve(res.text);
} catch(err) {
console.log(err);
run();
}
}
});
}
and I used the above function as:
const bigTranslation = await googleTranslator({ string: 'It looks like we’ll have to stand', from: 'en', to: 'es' });
return console.log(bigTranslation);
It worked perfectly till hours ago but now I get this error:
SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse () at consumeEnd (C:\inetpub\wwwroot\Server\node_modules\undici\lib\api\readable.js:237:20) at BodyReadable. (C:\inetpub\wwwroot\Server\node_modules\undici\lib\api\readable.js:219:7) at BodyReadable.emit (node:events:513:28) at BodyReadable.emit (C:\inetpub\wwwroot\Server\node_modules\undici\lib\api\readable.js:66:18) at endReadableNT (node:internal/streams/readable:1359:12) at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Why This is happening ?