mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-02-20 06:00:40 +01:00
Don't crash server if google translate fails
This commit is contained in:
parent
35349dd8d7
commit
45b714fb9e
@ -58,6 +58,7 @@ function registerEndpoints(app, jsonParser) {
|
||||
});
|
||||
|
||||
app.post('/api/translate/google', jsonParser, async (request, response) => {
|
||||
try {
|
||||
const { generateRequestUrl, normaliseResponse } = require('google-translate-api-browser');
|
||||
const text = request.body.text;
|
||||
const lang = request.body.lang;
|
||||
@ -78,14 +79,23 @@ function registerEndpoints(app, jsonParser) {
|
||||
});
|
||||
|
||||
resp.on('end', () => {
|
||||
try {
|
||||
const result = normaliseResponse(JSON.parse(data));
|
||||
console.log('Translated text: ' + result.text);
|
||||
return response.send(result.text);
|
||||
} catch (error) {
|
||||
console.log("Translation error", error);
|
||||
return response.sendStatus(500);
|
||||
}
|
||||
});
|
||||
}).on("error", (err) => {
|
||||
console.log("Translation error: " + err.message);
|
||||
return response.sendStatus(500);
|
||||
});
|
||||
} catch (error) {
|
||||
console.log("Translation error", error);
|
||||
return response.sendStatus(500);
|
||||
}
|
||||
});
|
||||
|
||||
app.post('/api/translate/deepl', jsonParser, async (request, response) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user