Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error Returns from current network handling are incomplete #48

Open
SquidLord opened this issue Jun 10, 2023 · 0 comments
Open

Error Returns from current network handling are incomplete #48

SquidLord opened this issue Jun 10, 2023 · 0 comments

Comments

@SquidLord
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant