Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an error code to NetConnectNotAllowedError #898

Merged
merged 1 commit into from
Sep 25, 2017

Conversation

reconbot
Copy link
Contributor

This is in line with nodejs error codes. I chose ENETUNREACH because it clearly defines the reason why the http request failed.

This helps testing when using an http request library that does retries as this isn't an error you would normally retry.

@coveralls
Copy link

coveralls commented May 11, 2017

Coverage Status

Coverage increased (+0.005%) to 92.691% when pulling 27112ae on reconbot:error-code into 17d7c25 on node-nock:master.

@paulmelnikow
Copy link
Member

As I articulated in #884, NetConnectNotAllowedError is a programmer error, not a runtime error. Nock should treat it less like a network error, not more. I would argue against this change.

@paulmelnikow
Copy link
Member

To say this another way:

  • To simulate a network error and trigger your application's error handling code, use .replyWithError({ code: 'ENETUNREACH' }).
  • To assert that a test does not make a network request, use .disableNetConnect().

@reconbot
Copy link
Contributor Author

I'm using tools that retry on recoverable errors but not others. (got) There's no standard error that says network is disabled, ENETUNREACH was the closest error code from the standard http error set that could be handled properly by downstream libraries.

@gr2m
Copy link
Member

gr2m commented Sep 23, 2017

@reconbot can you pass a function to the retry option that checks for the NetConnectNotAllowedError error name and use that as a way to not retry the request?

@reconbot
Copy link
Contributor Author

reconbot commented Sep 23, 2017 via email

@gr2m
Copy link
Member

gr2m commented Sep 23, 2017

I don’t understand what you mean Francis :) Is this PR still relevant for you or can we close it? And if it is, can you explain in more detail?

@reconbot
Copy link
Contributor Author

reconbot commented Sep 24, 2017

Say I have an application function

import got from 'got'
import {authHeaders} from './config'

export default function (url) {
   return got(url, { authHeaders, retries: 5 })
}

And I don't properly mock this request in my tests.

got will retry the request 5 times and probably timeout my test. got and my app have no knowledge of nock or any of the testing tools. It does however know about the standard errors returned by nodejs#errors. It's able to automatically not retry unrecoverable errors. This isn't unique to got, the aws-sdk has a similar behavior.

I don't want to import nock into my production deps to check to see if it's an instance of the NetConnectNotAllowedError.

I'm proposing we use a standard error code that suggests the requests shouldn't be retried when preventing a network connection. The specific code isn't important to me but I know ENETUNREACH is widely supported. It also clearly states the outcome of a disabled net connection. It is as if you really disabled your network connection.

@gr2m
Copy link
Member

gr2m commented Sep 25, 2017

I’m okay merging it. Could you rebase your PR on the latest master?

This is in line with nodejs error codes. I chose `ENETUNREACH` because it clearly defines the reason why the http request failed.

https://nodejs.org/api/all.html#errors_error_code
@coveralls
Copy link

coveralls commented Sep 25, 2017

Coverage Status

Coverage increased (+0.005%) to 92.691% when pulling 088e315 on reconbot:error-code into 66cd477 on node-nock:master.

@gr2m gr2m merged commit 4196cf0 into nock:master Sep 25, 2017
@reconbot reconbot deleted the error-code branch September 26, 2017 12:59
@lock
Copy link

lock bot commented Sep 13, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue and add a reference to this one if it’s related. Thank you!

@lock lock bot locked as resolved and limited conversation to collaborators Sep 13, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants