Skip to content

Commit

Permalink
handle failed policy set-version (yarnpkg#7848)
Browse files Browse the repository at this point in the history
* handle failed policy set-version

* linting

* handle instances where caseless is not defined on response
  • Loading branch information
olingern authored and VincentBailly committed Jun 10, 2020
1 parent b18ed7e commit 11ae40f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/cli/commands/policies.js
Expand Up @@ -124,9 +124,16 @@ const {run, setFlags, examples} = buildSubCommands('policies', {
bundleVersion = 'berry';
isV2 = true;
} else {
const releases = await fetchReleases(config, {
includePrereleases: allowRc,
});
let releases = [];

try {
releases = await fetchReleases(config, {
includePrereleases: allowRc,
});
} catch (e) {
reporter.error(e.message);
return;
}

const release = releases.find(release => {
// $FlowFixMe
Expand Down
1 change: 1 addition & 0 deletions src/reporters/lang/en.js
Expand Up @@ -358,6 +358,7 @@ const messages = {
errorExtractingTarball: 'Extracting tar content of $1 failed, the file appears to be corrupt: $0',
updateInstalling: 'Installing $0...',
hostedGitResolveError: 'Error connecting to repository. Please, check the url.',
unauthorizedResponse: 'Received a 401 from $0. $1',

unknownFetcherFor: 'Unknown fetcher for $0',

Expand Down
10 changes: 10 additions & 0 deletions src/util/request-manager.js
Expand Up @@ -373,6 +373,11 @@ export default class RequestManager {
rejectNext(err);
};

const rejectWithoutUrl = function(err) {
err.message = err.message;
rejectNext(err);
};

const queueForRetry = reason => {
const attempts = params.retryAttempts || 0;
if (attempts >= this.maxRetryAttempts - 1) {
Expand Down Expand Up @@ -428,6 +433,11 @@ export default class RequestManager {
}
}

if (res.statusCode === 401 && res.caseless && res.caseless.get('server') === 'GitHub.com') {
const message = `${res.body.message}. If using GITHUB_TOKEN in your env, check that it is valid.`;
rejectWithoutUrl(new Error(this.reporter.lang('unauthorizedResponse', res.caseless.get('server'), message)));
}

if (res.statusCode === 401 && res.headers['www-authenticate']) {
const authMethods = res.headers['www-authenticate'].split(/,\s*/).map(s => s.toLowerCase());

Expand Down

0 comments on commit 11ae40f

Please sign in to comment.