Closed jp1987 closed 6 years ago
This is mostly based on #12, but that has been inactive for over 3 years now and we REALLY need this. I used pretty much the same logic, except for using a promise reject when catching the error, that seems to make the most sense to me. Would be great if we could get this merged.
Just curious, is there any reason you're not bubbling up the request error as-is instead of wrapping it in another Error object?
When swagger encounters an error it causes the library to emit an "APILoadError" event. Seems like it'd be good to keep that even if the host is not reachable.
Processed your feedback @chadxz
is there any reason you're not bubbling up the request error as-is instead of wrapping it in another Error object?
^This still isn't clear to me. I haven't dug into the request implementation, but I wonder if assuming that the host is not reachable is the reason the error occurred is a correct assumption.
Also, I'm not entirely sure what sort of version bump this would be. Adding a new error scenario that wasn't there before seems to me to be a major version bump.
Sorry, I'm not sure what you mean by "I wonder if assuming that the host is not reachable is the reason the error occurred is a correct assumption". Can you elaborate?
I upped the version to 1.2.0 and updated the changelog.
In your code you are treating any error from request as if it is caused by the host being unreachable. I'm asking- is this the right thing to do? Are there other classes of problems that the user may want to know about that we are re-casting as a "host not reachable" error?
Right, I see what you mean. I looked into the request lib and they appear to use the native http module, which has the following error codes (exhaustive list).
To me it makes the most sense to watch for ETIMEDOUT, ENOTFOUND and ECONNREFUSED. So I am filtering for these now.
ETIMEDOUT is a bit tricky to write a test case for (example here), which would require a bit of an overhaul of tests/helpers.js (it needs to return another client that simulates the timeout), so I've skipped that for now (basically all that it would test is the indexOf function, which the other 2 test cases now cover).
Can we get this merged then?
Who wants to merge and release?
Sam's gonna do it
Tagged and published to NPM.
@jp1987 thank you for your contribution!
Fixes #35