Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle failed policy set-version #7848

Merged
merged 3 commits into from
Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 12 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,13 @@ export default class RequestManager {
}
}

const server = res.caseless.get('server');

if (res.statusCode === 401 && server === "GitHub.com") {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if a constant is worth using here. Request manager is probably too generic in some ways. Would be nice to have a Github only request manager so stuff like this could be avoided. For now, I don't think this is terrible.

const message = `${res.body.message}. If using GITHUB_TOKEN in your env, check that it is valid.`
rejectWithoutUrl(new Error(this.reporter.lang('unauthorizedResponse', server, message)))
}

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

Expand Down