feat: Add error management for new follower of me trigger
This commit is contained in:
@@ -13,7 +13,14 @@ const getUserFollowers = async (
|
|||||||
options: GetUserFollowersOptions
|
options: GetUserFollowersOptions
|
||||||
) => {
|
) => {
|
||||||
let response;
|
let response;
|
||||||
const followers: IJSONObject[] = [];
|
|
||||||
|
const followers: {
|
||||||
|
data: IJSONObject[];
|
||||||
|
error: IJSONObject | null;
|
||||||
|
} = {
|
||||||
|
data: [],
|
||||||
|
error: null,
|
||||||
|
};
|
||||||
|
|
||||||
do {
|
do {
|
||||||
const params: IJSONObject = {
|
const params: IJSONObject = {
|
||||||
@@ -31,13 +38,23 @@ const getUserFollowers = async (
|
|||||||
method: 'GET',
|
method: 'GET',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (response.integrationError) {
|
||||||
|
followers.error = response.integrationError;
|
||||||
|
return followers;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.data?.errors) {
|
||||||
|
followers.error = response.data.errors;
|
||||||
|
return followers;
|
||||||
|
}
|
||||||
|
|
||||||
if (response.data.meta.result_count > 0) {
|
if (response.data.meta.result_count > 0) {
|
||||||
response.data.data.forEach((tweet: IJSONObject) => {
|
response.data.data.forEach((tweet: IJSONObject) => {
|
||||||
if (
|
if (
|
||||||
!options.lastInternalId ||
|
!options.lastInternalId ||
|
||||||
Number(tweet.id) > Number(options.lastInternalId)
|
Number(tweet.id) > Number(options.lastInternalId)
|
||||||
) {
|
) {
|
||||||
followers.push(tweet);
|
followers.data.push(tweet);
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -45,14 +62,6 @@ const getUserFollowers = async (
|
|||||||
}
|
}
|
||||||
} while (response.data.meta.next_token && options.lastInternalId);
|
} while (response.data.meta.next_token && options.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 followers;
|
return followers;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user