mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
feat: return translation not supported error to the frontend
This commit is contained in:
parent
91b82c36a8
commit
54fa38795a
3 changed files with 10 additions and 1 deletions
|
|
@ -132,7 +132,10 @@ const translateController: AppController = async (c) => {
|
|||
|
||||
dittoTranslations.set(translatedId, { data: mastodonTranslation });
|
||||
return c.json(mastodonTranslation, 200);
|
||||
} catch {
|
||||
} catch (e: any) {
|
||||
if (e.message?.includes('not supported') || e.error?.includes('not supported')) {
|
||||
return c.json({ error: `Translation of source language '${event.language}' not supported` }, 422);
|
||||
}
|
||||
return c.json({ error: 'Service Unavailable' }, 503);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -68,6 +68,9 @@ export class DeepLTranslator implements DittoTranslator {
|
|||
|
||||
const response = await this.fetch(request);
|
||||
const json = await response.json();
|
||||
if (!response.ok) {
|
||||
throw json;
|
||||
}
|
||||
const data = DeepLTranslator.schema().parse(json);
|
||||
|
||||
return data;
|
||||
|
|
|
|||
|
|
@ -68,6 +68,9 @@ export class LibreTranslateTranslator implements DittoTranslator {
|
|||
|
||||
const response = await this.fetch(request);
|
||||
const json = await response.json();
|
||||
if (!response.ok) {
|
||||
throw json;
|
||||
}
|
||||
const data = LibreTranslateTranslator.schema().parse(json);
|
||||
|
||||
return data;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue