Skip to content

Commit 61f065a

Browse files
j1mb0-1owlstronaut
authored andcommitted
fix: use statusCode instead of constructor name for tarball fallback in git fetcher
1 parent 644ebb6 commit 61f065a

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

lib/git.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ class GitFetcher extends Fetcher {
255255
integrity: null, // it'll always be different, if we have one
256256
}).extract(tmp).then(() => handler(`${tmp}${this.spec.gitSubdir || ''}`), er => {
257257
// fall back to ssh download if tarball fails
258-
if (er.constructor.name.match(/^Http/)) {
258+
if (typeof er.statusCode === 'number' && er.statusCode >= 400) {
259259
return this.#clone(handler, false)
260260
} else {
261261
throw er

test/git.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const rimraf = require('rimraf')
1515
const tar = require('tar')
1616
const spawnNpm = require('../lib/util/npm.js')
1717
const GitFetcher = require('../lib/git.js')
18+
const RemoteFetcher = require('../lib/remote.js')
1819

1920
// set this up first, so we can use 127.0.0.1 as our "hosted git" service
2021
const httpPort = 18000 + (+process.env.TAP_CHILD_ID || 0)
@@ -631,6 +632,22 @@ t.test('fetch a private repo where the tgz is a 404', { skip: isWindows && 'posi
631632
return gf.extract(me + '/no-tgz')
632633
})
633634

635+
t.test('fetch a private repo where the tgz is a 404 and http error has minified class name',
636+
{ skip: isWindows && 'posix only' }, async t => {
637+
const gf = new GitFetcher(`localhost:repo/x#${REPO_HEAD}`, opts)
638+
const origExtract = RemoteFetcher.prototype.extract
639+
RemoteFetcher.prototype.extract = () => {
640+
const err = new Error('404 Not Found')
641+
err.statusCode = 404
642+
err.code = 'E404'
643+
return Promise.reject(err)
644+
}
645+
t.teardown(() => {
646+
RemoteFetcher.prototype.extract = origExtract
647+
})
648+
await gf.extract(me + '/no-tgz')
649+
})
650+
634651
t.test('fetch a private repo where the tgz is not a tarball', { skip: isWindows && 'posix only' },
635652
t => {
636653
const gf = new GitFetcher(`localhost:repo/x#${REPO_HEAD}`, opts)

0 commit comments

Comments
 (0)