Skip to content

Instantly share code, notes, and snippets.

@trentm
Created June 28, 2012 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trentm/3013102 to your computer and use it in GitHub Desktop.
Save trentm/3013102 to your computer and use it in GitHub Desktop.
npm retry on 408 or 5xx only
Index: /Users/trentm/tm/npm/node_modules/npm-registry-client/lib/request.js
index cba8ba2..7781d37 100644
--- a/node_modules/npm-registry-client/lib/request.js
+++ b/node_modules/npm-registry-client/lib/request.js
@@ -88,8 +88,11 @@ function regRequest (method, where, what, etag, nofollow, cb_) {
self.log.info("retry", "registry request attempt " + currentAttempt
+ " at " + (new Date()).toLocaleTimeString())
makeRequest.call(self, method, remote, where, what, etag, nofollow
- , function (er) {
- if (operation.retry(er)) {
+ , function (er, parsed, raw, response) {
+ // Only retry on 408, 5xx or no `response`.
+ var statusCode = response && response.statusCode
+ var statusRetry = !statusCode || (statusCode === 408 || statusCode >= 500)
+ if (er && statusRetry && operation.retry(er)) {
self.log.info("retry", "will retry, error on last attempt: " + er)
return
}
$ touch proxy.js && sleep 1 && rm -rf tmp/cache node_modules/bunyan && node ~/tm/npm/cli.js --loglevel=info --cache=`pwd`/tmp/cache --registry=http://localhost:8000/ install jsontoolXXX
npm info it worked if it ends with ok
npm info using npm@1.1.32
npm info using node@v0.6.19
npm info retry registry request attempt 1 at 11:21:14
npm http GET http://localhost:8000/jsontoolXXX
npm http 404 http://localhost:8000/jsontoolXXX
npm ERR! 404 'jsontoolXXX' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, or http url, or git url.
npm ERR! System Darwin 10.8.0
npm ERR! command "node" "/Users/trentm/tm/npm/cli.js" "--loglevel=info" "--cache=/Users/trentm/tm/npm-registry-proxy/tmp/cache" "--registry=http://localhost:8000/" "install" "jsontoolXXX"
npm ERR! cwd /Users/trentm/tm/npm-registry-proxy
npm ERR! node -v v0.6.19
npm ERR! npm -v 1.1.32
npm ERR! code E404
npm ERR! message 404 Not Found: jsontoolXXX
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/trentm/tm/npm-registry-proxy/npm-debug.log
npm ERR! not ok code undefined
npm ERR! not ok code 1
$ touch proxy.js && sleep 1 && rm -rf tmp/cache node_modules/bunyan && node ~/tm/npm/cli.js --loglevel=info --cache=`pwd`/tmp/cache --registry=http://localhost:8000/ install bunyan
npm info it worked if it ends with ok
npm info using npm@1.1.32
npm info using node@v0.6.19
npm info retry registry request attempt 1 at 11:29:56
npm http GET http://localhost:8000/bunyan
npm http 500 http://localhost:8000/bunyan
npm info retry will retry, error on last attempt: 500 Internal Server Error
npm info retry registry request attempt 2 at 11:30:07
npm http GET http://localhost:8000/bunyan
npm http 200 http://localhost:8000/bunyan
npm info retry fetch attempt 1 at 11:30:07
npm http GET http://localhost:8000/bunyan/-/bunyan-0.10.0.tgz
npm http 200 http://localhost:8000/bunyan/-/bunyan-0.10.0.tgz
npm info shasum 51b6270f4e6f151a6eaf9a9f188acaebec2101eb
npm info shasum /var/folders/a1/a1q548caE+ytwn0liWfg7E+++TI/-Tmp-/npm-46567/1340908207469-0.8552755743730813/tmp.tgz
npm info shasum 51b6270f4e6f151a6eaf9a9f188acaebec2101eb
npm info shasum /Users/trentm/tm/npm-registry-proxy/tmp/cache/bunyan/0.10.0/package.tgz
npm info install bunyan@0.10.0 into /Users/trentm/tm/npm-registry-proxy
npm info installOne bunyan@0.10.0
npm info /Users/trentm/tm/npm-registry-proxy/node_modules/bunyan unbuild
npm info preinstall bunyan@0.10.0
npm info build /Users/trentm/tm/npm-registry-proxy/node_modules/bunyan
npm info linkStuff bunyan@0.10.0
npm info install bunyan@0.10.0
npm info postinstall bunyan@0.10.0
bunyan@0.10.0 node_modules/bunyan
npm info ok
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment