Skip to content

Commit

Permalink
When tarball fetches fail, report the status code instead of "invalid…
Browse files Browse the repository at this point in the history
… tar" (#1958)
  • Loading branch information
KidkArolis authored and bestander committed Dec 4, 2016
1 parent 5d0d402 commit 68df0ea
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/fetchers/tarball-fetcher.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @flow */

import http from 'http';
import {SecurityError, MessageError} from '../errors.js';
import type {FetchedOverride} from '../types.js';
import {UnpackStream} from '../util/stream.js';
Expand Down Expand Up @@ -157,6 +158,7 @@ export default class TarballFetcher extends BaseFetcher {
},
buffer: true,
process: (req, resolve, reject) => {
const {reporter} = this.config;
// should we save this to the offline cache?
const mirrorPath = this.getMirrorPath();
const tarballStorePath = path.join(this.dest, constants.TARBALL_FILENAME);
Expand All @@ -170,7 +172,17 @@ export default class TarballFetcher extends BaseFetcher {
extractorStream,
} = this.createExtractor(overwriteResolved, resolve, reject);

//
const handleRequestError = (res) => {
if (res.statusCode >= 400) {
// $FlowFixMe
const statusDescription = http.STATUS_CODES[res.statusCode];
reject(new Error(
reporter.lang('requestFailed', `${res.statusCode} ${statusDescription}`),
));
}
};

req.on('response', handleRequestError);
req.pipe(validateStream);

validateStream
Expand Down
1 change: 1 addition & 0 deletions src/reporters/lang/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ const messages = {
cantRequestOffline: 'Can\'t make a request in offline mode',
requestManagerNotSetupHAR: 'RequestManager was not setup to capture HAR files',
requestError: 'Request $0 returned a $1',
requestFailed: 'Request failed $0',
tarballNotInNetworkOrCache: '$0: Tarball is not in network and can not be located in cache ($1)',
fetchBadHash: 'Bad hash. Expected $0 but got $1 ',
fetchErrorCorrupt: '$0. Mirror tarball appears to be corrupt. You can resolve this by running:\n\n $ rm -rf $1\n $ yarn install',
Expand Down

0 comments on commit 68df0ea

Please sign in to comment.