Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/cli/commands/policies.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,16 @@ const {run, setFlags, examples} = buildSubCommands('policies', {
bundleUrl = 'https://github.com/yarnpkg/berry/raw/master/packages/berry-cli/bin/berry.js';
bundleVersion = 'berry';
} else {
const releases = await fetchReleases(config, {
includePrereleases: allowRc,
});
let releases = [];

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the event of a promise rejection, report and return early

}

const release = releases.find(release => {
// $FlowFixMe
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 @@ -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
Original file line number Diff line number Diff line change
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