refactor: throw new Error to have benefit of stack trace

This commit is contained in:
P. Reis 2024-10-09 19:17:03 -03:00
parent 54fa38795a
commit 87e0f594df
3 changed files with 3 additions and 3 deletions

View file

@ -133,7 +133,7 @@ const translateController: AppController = async (c) => {
dittoTranslations.set(translatedId, { data: mastodonTranslation }); dittoTranslations.set(translatedId, { data: mastodonTranslation });
return c.json(mastodonTranslation, 200); return c.json(mastodonTranslation, 200);
} catch (e: any) { } catch (e: any) {
if (e.message?.includes('not supported') || e.error?.includes('not supported')) { if (e.message?.includes('not supported')) {
return c.json({ error: `Translation of source language '${event.language}' not supported` }, 422); return c.json({ error: `Translation of source language '${event.language}' not supported` }, 422);
} }
return c.json({ error: 'Service Unavailable' }, 503); return c.json({ error: 'Service Unavailable' }, 503);

View file

@ -69,7 +69,7 @@ export class DeepLTranslator implements DittoTranslator {
const response = await this.fetch(request); const response = await this.fetch(request);
const json = await response.json(); const json = await response.json();
if (!response.ok) { if (!response.ok) {
throw json; throw new Error(json['message']);
} }
const data = DeepLTranslator.schema().parse(json); const data = DeepLTranslator.schema().parse(json);

View file

@ -69,7 +69,7 @@ export class LibreTranslateTranslator implements DittoTranslator {
const response = await this.fetch(request); const response = await this.fetch(request);
const json = await response.json(); const json = await response.json();
if (!response.ok) { if (!response.ok) {
throw json; throw new Error(json['error']);
} }
const data = LibreTranslateTranslator.schema().parse(json); const data = LibreTranslateTranslator.schema().parse(json);