Skip to content

Error Returns from current network handling are incomplete #48

@SquidLord

Description

@SquidLord

The message is returned to the user in the case of some kind of failure by the Tweet endpoint is incomplete.

The changes necessary would be on the order of:

try {  
  tweetRequest = await request({  
    method: 'GET',  
    url: `${twitterUrl.href}?${params.toString()}`,  
    headers: {Authorization: `Bearer ${bearer}`},  
  })  
} catch (error) {  
  if (error.request) {  
-   throw new Error('There seems to be a connection issue.')  
+   if (error.response) {
+     let errorMessage = `Received status code ${error.response.status}.`;
+     if (error.response.data && error.response.data.errors) {
+       const errorDetails = error.response.data.errors.map(err => err.detail).join(', ');
+       errorMessage += ` Error details: ${errorDetails}`;
+     }
+     throw new Error(errorMessage);
+   } else {
+     throw new Error('No response received from the server. This may be a connection issue.');
+   }
  } else {  
    console.error(error)  
    throw error  
  }  
}  
const tweet: Tweet = JSON.parse(tweetRequest);

But I am not at this moment able to make and test the updated code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions