chore: Use integrationError instead of automatischError
This commit is contained in:
@@ -53,8 +53,8 @@ export default class SearchTweets {
|
|||||||
headers: { ...authHeader },
|
headers: { ...authHeader },
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.automatischError) {
|
if (response.integrationError) {
|
||||||
tweets.error = response.automatischError;
|
tweets.error = response.integrationError;
|
||||||
return tweets;
|
return tweets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
import axios, { AxiosInstance } from 'axios';
|
import axios, { AxiosInstance, AxiosResponse } from 'axios';
|
||||||
import { IJSONObject, IHttpClientParams } from '@automatisch/types';
|
import { IJSONObject, IHttpClientParams } from '@automatisch/types';
|
||||||
|
|
||||||
|
type ExtendedAxiosResponse = AxiosResponse & { integrationError: IJSONObject };
|
||||||
|
|
||||||
export default class HttpClient {
|
export default class HttpClient {
|
||||||
instance: AxiosInstance;
|
instance: AxiosInstance;
|
||||||
|
|
||||||
@@ -8,18 +10,25 @@ export default class HttpClient {
|
|||||||
this.instance = axios.create({
|
this.instance = axios.create({
|
||||||
baseURL: params.baseURL,
|
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) {
|
async get(path: string, options?: IJSONObject) {
|
||||||
try {
|
return (await this.instance.get(path, options)) as ExtendedAxiosResponse;
|
||||||
return await this.instance.get(path, options);
|
|
||||||
} catch (error) {
|
|
||||||
error.response.automatischError = error.response.data;
|
|
||||||
return error.response;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async post(path: string, body: IJSONObject | string, options?: IJSONObject) {
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user