Basic error handling for API responses added#7
Basic error handling for API responses added#7inadarei wants to merge 1 commit intoseebees:masterfrom
Conversation
|
Let me take a look. I'll do some wirk and merge stuff tomorow.
|
|
Awesome! Many thanks. |
|
@inadarei So the only thing is I don't want to throw. Because the callback my not be wrapped in a domain. What would you think of something like this: if (response.statusCode > 399) {
var errMsg = util.format("%s %s %s %s %d %s %j \n", "API request to Iron.io failed."
, "\nRequest URL:"
, response.request.uri.href
, "\nResponse Code: "
, response.statusCode
, "\nError Message: "
, JSON.parse(response.body))
cb(response.statusCode, errMsg)
} |
|
Yes. Returning error rather than throwing sounds much better. I don't remember why my pull request was throwing an error, tbh. It was a while ago :) The code you posted looks better |
I saw that error-handling for the project is still TBD.
This pull request does not handle all and any kind of errors, but at least it throws some additional info if the API responds with HTTP 400 or 404 or 500.
Basically, I had a malformed list of init parameters and was getting "calling .map() on undefined" instead of a helpful message, so I think it would help in similar cases :)
If you could merge the pull and re-publish npm, it would be super!
Thanks for the project!