Added try/catch to mastodon micro-service

This commit is contained in:
Jyotirmoy Bandyopadhayaya 2023-03-09 11:20:46 +05:30
parent b6630790cc
commit 2e4af394f9
Signed by: bravo68web
GPG Key ID: F5671FD7BCB9917A
2 changed files with 18 additions and 5 deletions

View File

@ -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))
}
}
}

View File

@ -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
}