diff --git a/packages/api/controllers/mastodon.controller.ts b/packages/api/controllers/mastodon.controller.ts index 09258f2..b3532f6 100644 --- a/packages/api/controllers/mastodon.controller.ts +++ b/packages/api/controllers/mastodon.controller.ts @@ -4,12 +4,22 @@ import { Request, Response } from 'express' export default class MastodonController extends MastodonService { public fetchMastodonProfile = async (req: Request, res: Response) => { - const data = await this.getMastodonProfile() - return res.send(makeResponse(data)) + try{ + const data = await this.getMastodonProfile() + return res.send(makeResponse(data)) + } + catch (err: any){ + res.send(makeResponse(err.message, {}, 'Failed', true)) + } } public fetchMastodonStatuses = async (req: Request, res: Response) => { - const data = await this.getMastodonStatuses() - return res.send(makeResponse(data)) + try { + const data = await this.getMastodonStatuses() + return res.send(makeResponse(data)) + } + catch (err: any) { + res.send(makeResponse(err.message, {}, 'Failed', true)) + } } } diff --git a/packages/api/services/mastodon.service.ts b/packages/api/services/mastodon.service.ts index 31601ce..41136e3 100644 --- a/packages/api/services/mastodon.service.ts +++ b/packages/api/services/mastodon.service.ts @@ -10,7 +10,10 @@ export default class MastodonService { public getMastodonStatuses = async () => { const { data } = await axiosInstance.get( - 'https://fosstodon.org/api/v1/accounts/109612266657666903/statuses' + 'https://fosstodon.org/api/v1/accounts/109612266657666903/statuses', + { + timeout: 10000 + } ) return data }