feat: Draft implementation to store and expose integration errors

This commit is contained in:
Faruk AYDIN
2022-09-19 12:13:36 +03:00
parent d0bcf997fb
commit 8826125845
3 changed files with 47 additions and 21 deletions

View File

@@ -19,7 +19,13 @@ export default class SearchTweets {
};
let response;
const tweets: IJSONObject[] = [];
const tweets: {
data: IJSONObject[];
error: IJSONObject | null;
} = {
data: [],
error: null,
};
do {
const params: IJSONObject = {
@@ -47,10 +53,15 @@ export default class SearchTweets {
headers: { ...authHeader },
});
if (response.automatischError) {
tweets.error = response.automatischError;
return tweets;
}
if (response.data.meta.result_count > 0) {
response.data.data.forEach((tweet: IJSONObject) => {
if (!lastInternalId || Number(tweet.id) > Number(lastInternalId)) {
tweets.push(tweet);
tweets.data.push(tweet);
} else {
return;
}
@@ -58,16 +69,6 @@ export default class SearchTweets {
}
} while (response.data.meta.next_token && lastInternalId);
if (response.data?.errors) {
const errorMessages = response.data.errors
.map((error: IJSONObject) => error.detail)
.join(' ');
throw new Error(
`Error occured while fetching user data: ${errorMessages}`
);
}
return tweets;
}
}