Skip to content

Commit

Permalink
docs: Add "Common issues" section documenting got automatic retrying (#…
Browse files Browse the repository at this point in the history
…1687)

Closes #1661
  • Loading branch information
paulmelnikow committed Aug 23, 2019
1 parent 8e78ffe commit ad000ef
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions README.md
Expand Up @@ -87,6 +87,7 @@ For instance, if a module performs HTTP requests to a CouchDB server or makes HT
- [Options](#options-1)
- [Example](#example)
- [Modes](#modes)
- [Common issues](#common-issues)
- [Debugging](#debugging)
- [Contributing](#contributing)
- [Contributors](#contributors)
Expand Down Expand Up @@ -1482,6 +1483,37 @@ To set the mode call `nockBack.setMode(mode)` or run the tests with the `NOCK_BA
- lockdown: use recorded nocks, disables all http calls even when not nocked, doesn't record
## Common issues
**"No match for response" when using got with error responses**
[Got][] automatically retries failed requests twice. That means if you have a
test which mocks a 4xx or 5xx response, got will immediately reissue it. At
that point, the mock will have been consumed and the second request will error
out with **Nock: No match for request**.
The same is true for `.replyWithError()`.
Adding `{ retry: 0 }` to the `got` invocations will disable retrying, e.g.:
```
await got("http://example.test/", { retry: 0 })
```
If you need to do this in all your tests, you can create a module
`got_client.js` which exports a custom got instance:
```
const got = require('got')

module.exports = got.extend({ retry: 0 })
```
This is how it's handled in Nock itself (see [#1523][]).
[got]: https://github.com/sindresorhus/got
[#1523]: https://github.com/nock/nock/issues/1523
## Debugging
Nock uses [`debug`](https://github.com/visionmedia/debug), so just run with environmental variable `DEBUG` set to `nock.*`.
Expand Down

0 comments on commit ad000ef

Please sign in to comment.