Trying to translate a text with quotes in it fails.
A translation error causes the process to crash instead of being handled with try-catch.
Steps to reproduce
import { translate } from 'google-translate-api-browser';
async function translateText(text, lang) {
try {
const result = await translate(text, { to: lang });
console.log(result.text);
} catch (error) {
console.log('Translation error: ' + error);
}
}
await translateText('The cat cannot speak like humans, it just makes cat noises such as "meow", and it doesn\'t even know English', 'es');
export { };
Expected result
Translated text displays in the console.
Actual result
Node process crashes, try-catch not executed. Crash logs read: Error: Data is either empty or corrupted
Doing a request with fetch instead gives this response:
Bad Request )]}'
102
[["er",null,null,null,null,400,null,null,null,3],["di",10],["af.httprm",9,"3737202303121642252",34]]
25
[["e",4,null,null,138]]
Environment Package version: 4.2.4 Node version: v20.9.0 OS: Windows 11 22H2
Description
Steps to reproduce
Expected result Translated text displays in the console.
Actual result Node process crashes, try-catch not executed. Crash logs read:
Error: Data is either empty or corrupted
Doing a request with fetch instead gives this response: