Object.keys safety for missing data

This commit is contained in:
dangered wolf 2023-08-23 17:00:27 -04:00
parent 05e106b295
commit aba1cbbf5e
No known key found for this signature in database
GPG key ID: 41E4D37680ED8B58

View file

@ -300,7 +300,7 @@ export const fetchConversation = async (
return true; return true;
} }
console.log('invalid graphql tweet'); console.log('invalid graphql tweet');
if (!tweet && typeof conversation.data?.tweetResult === 'object' && Object.keys(conversation.data?.tweetResult).length === 0) { if (!tweet && typeof conversation.data?.tweetResult === 'object' && Object.keys(conversation.data?.tweetResult || {}).length === 0) {
console.log('tweet was not found'); console.log('tweet was not found');
return true; return true;
} }
@ -350,7 +350,7 @@ export const fetchUser = async (
(_res: unknown) => { (_res: unknown) => {
const response = _res as GraphQLUserResponse; const response = _res as GraphQLUserResponse;
// If _res.data is an empty object, we have no user // If _res.data is an empty object, we have no user
if (!Object.keys(response?.data).length) { if (!Object.keys(response?.data || {}).length) {
console.log(`response.data is empty, can't continue`); console.log(`response.data is empty, can't continue`);
return false; return false;
} }