ibrod83 / nodejs-file-downloader

130 stars 23 forks source link

Send the response body in the error #29

Closed IonicaBizau closed 2 years ago

IonicaBizau commented 2 years ago

First of all, thank you for the amazing module! ⭐

It would be great to get the response body in case of error and send it in the error handler.

Usecase Using the GitHub API to download the tarball, if the response is invalid, we can only know that it failed (e.g. 403), but the response body would contain the reason why it failed.

ibrod83 commented 2 years ago

You mean this? https://github.com/ibrod83/nodejs-file-downloader#getting-the-response-object-during-an-error

Note that it's not very friendly, it just exposes the stream object, but if you follow the example you can get what you need. I plan to make it more axios-like in the future

IonicaBizau commented 2 years ago

Exactly! That would make it more convenient if it were part of the library codebase.

On Tue, Dec 28, 2021 at 5:51 PM ibrod83 @.***> wrote:

You mean this?

https://github.com/ibrod83/nodejs-file-downloader#getting-the-response-object-during-an-error

Note that it's not very friendly, it just exposes the stream object, but if you follow the example you can get what you need. I plan to make it more axios-like in the future

— Reply to this email directly, view it on GitHub https://github.com/ibrod83/nodejs-file-downloader/issues/29#issuecomment-1002194481, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAV3J4ZH46QAKCXNKA4NA3DUTHTJXANCNFSM5K4HTF3A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

ibrod83 commented 2 years ago

I've added a reference to the response body. Now it should work as u expect. Note that the property you need to access is error.responseBody. If you have an existing code streaming error.response, it will fail to work as expected. Upgrade to latest version and tell me how it went :D

IonicaBizau commented 2 years ago

Thank you! That is so cool and will be helpful for debugging. :) happy new year and keep up the great work!

Sent from my iPhone

On 31 Dec 2021, at 15:20, ibrod83 @.***> wrote:

 I've added a reference to the response body. Now it should work as u expect. Note that the property you need to access is error.responseBody. If you have an existing code streaming error.response, it will fail to work as expected. Upgrade to latest version and tell me how it went :D

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you authored the thread.