diff --git a/packages/backend/src/apps/twitter/client/endpoints/search-tweets.ts b/packages/backend/src/apps/twitter/client/endpoints/search-tweets.ts index bd138c26..89eddeba 100644 --- a/packages/backend/src/apps/twitter/client/endpoints/search-tweets.ts +++ b/packages/backend/src/apps/twitter/client/endpoints/search-tweets.ts @@ -53,8 +53,8 @@ export default class SearchTweets { headers: { ...authHeader }, }); - if (response.automatischError) { - tweets.error = response.automatischError; + if (response.integrationError) { + tweets.error = response.integrationError; return tweets; } diff --git a/packages/backend/src/helpers/http-client/index.ts b/packages/backend/src/helpers/http-client/index.ts index ab8e103b..8c0861c7 100644 --- a/packages/backend/src/helpers/http-client/index.ts +++ b/packages/backend/src/helpers/http-client/index.ts @@ -1,6 +1,8 @@ -import axios, { AxiosInstance } from 'axios'; +import axios, { AxiosInstance, AxiosResponse } from 'axios'; import { IJSONObject, IHttpClientParams } from '@automatisch/types'; +type ExtendedAxiosResponse = AxiosResponse & { integrationError: IJSONObject }; + export default class HttpClient { instance: AxiosInstance; @@ -8,18 +10,25 @@ export default class HttpClient { this.instance = axios.create({ baseURL: params.baseURL, }); + + this.instance.interceptors.response.use( + (response) => response, + (error) => { + error.response.integrationError = error.response.data; + return error.response; + } + ); } async get(path: string, options?: IJSONObject) { - try { - return await this.instance.get(path, options); - } catch (error) { - error.response.automatischError = error.response.data; - return error.response; - } + return (await this.instance.get(path, options)) as ExtendedAxiosResponse; } async post(path: string, body: IJSONObject | string, options?: IJSONObject) { - return await this.instance.post(path, body, options); + return (await this.instance.post( + path, + body, + options + )) as ExtendedAxiosResponse; } }