1 |
|
2 | # superagent-retry
|
3 |
|
4 | Extends the node version of [`visionmedia/superagent`][superagent]'s `Request`, adds a `.retry` method to add retrying logic to the request. Calling this will retry the request however many additional times you'd like.
|
5 |
|
6 |
|
7 | [superagent]: https://github.com/visionmedia/superagent
|
8 |
|
9 | ## Usage
|
10 |
|
11 | ```javascript
|
12 | var superagent = require('superagent');
|
13 | require('superagent-retry')(superagent');
|
14 |
|
15 | superagent
|
16 | .get('https://segment.io')
|
17 | .retry(2) // retry twice before responding
|
18 | .end(onresponse);
|
19 |
|
20 |
|
21 | function onresponse (res) {
|
22 | console.log(res.status, res.headers);
|
23 | console.log(res.body);
|
24 | }
|
25 | ```
|
26 |
|
27 | ## Retrying Cases
|
28 |
|
29 | Currently the retrying logic checks for:
|
30 |
|
31 | * ECONNRESET
|
32 | * ETIMEDOUT
|
33 | * EADDRINFO
|
34 | * ESOCKETTIMEDOUT
|
35 | * superagent client timeouts
|
36 | * bad gateway errors (503s)
|
37 |
|
38 |
|
39 | ## License
|
40 |
|
41 | (The MIT License)
|
42 |
|
43 | Copyright (c) 2013 Segmentio <friends@segment.io>
|
44 |
|
45 | Permission is hereby granted, free of charge, to any person obtaining
|
46 | a copy of this software and associated documentation files (the
|
47 | 'Software'), to deal in the Software without restriction, including
|
48 | without limitation the rights to use, copy, modify, merge, publish,
|
49 | distribute, sublicense, and/or sell copies of the Software, and to
|
50 | permit persons to whom the Software is furnished to do so, subject to
|
51 | the following conditions:
|
52 |
|
53 | The above copyright notice and this permission notice shall be
|
54 | included in all copies or substantial portions of the Software.
|
55 |
|
56 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
57 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
58 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
59 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
60 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
61 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
62 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
\ | No newline at end of file |