refactor: cast correct error type

This commit is contained in:
P. Reis 2024-10-09 19:19:54 -03:00
parent 87e0f594df
commit b86bd81ed2

View file

@ -132,8 +132,8 @@ 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) {
if (e.message?.includes('not supported')) { if (e instanceof Error && 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);