chore: Use integrationError instead of automatischError

This commit is contained in:
Faruk AYDIN
2022-09-26 19:12:07 +03:00
parent 8826125845
commit 953a031ba6
2 changed files with 19 additions and 10 deletions

View File

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

View File

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