Error Returns from current network handling are incomplete
SquidLord opened this issue · comments
Alexander Williams commented
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.