brianleroux / tiny-json-http

:anchor: Minimalist HTTP client for JSON payloads.
172 stars 18 forks source link

forwarding http error context #6

Closed danprince closed 7 years ago

danprince commented 7 years ago

Sorry! You can't get rid of me today, I'm afraid.

I'm trying to implement some logic for retrying requests after Slack imposes a rate limit, where they respond with a 429 and send a Retry-After header.

The errors I'm catching are regular error objects with the message: "POST failed with: 429" and no additional context.

Ideally, tiny-json-http would expose the underlying HTTP response on the error property so that we could get at the headers and status code directly.

brianleroux commented 7 years ago

haha np! yea I've wanted this myself. guess the hack could be here

https://github.com/brianleroux/tiny-json-http/blob/master/_write.js#L40

var err = Error(httpMethod + ' failed with: ' + res.statusCode)
err.raw =  Buffer.concat(raw).toString()
callback(err)
brianleroux commented 7 years ago

fixed in 5.2 thx to @danprince 🔥 🔥 🔥