mirror of
https://github.com/aljazceru/ditto.git
synced 2026-02-01 03:24:19 +01:00
feat: return translation not supported error to the frontend
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user