From 8a49924f3484f67d71b14531ff11c47790f49f5b Mon Sep 17 00:00:00 2001 From: Nick Doering Date: Wed, 19 Jul 2017 15:30:37 -0700 Subject: [PATCH] Add basic feedback for unauthorized users. --- src/backends/github/implementation.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/backends/github/implementation.js b/src/backends/github/implementation.js index 9c98a5540bcb..a1df6e558e2e 100644 --- a/src/backends/github/implementation.js +++ b/src/backends/github/implementation.js @@ -31,17 +31,20 @@ export default class GitHub { authenticate(state) { this.token = state.token; this.api = new API({ token: this.token, branch: this.branch, repo: this.repo, api_root: this.api_root }); - return this.api.user().then(user => ( + return this.api.user().then(user => this.api.collaborator(user.login).then((status) => { - if (status === 404) { + if (status === 404 || status === 403) { // Unauthorized user - throw new Error('You don\'t have publishing access.\nIf you think this is incorrrect, talk to the site administrator.'); + alert("Sorry, but you don't appear to have publisher access. If you think this is incorrect, talk to the site administrator"); + throw new Error('Talk to the site administrator to get publishing access.'); + } else if (status === 204) { + // Authorized user + user.token = state.token; + return user; } - // Authorized user - user.token = state.token; - return user; + throw new Error('No response from Github, that\'s odd.'); }) - )); + ); } getToken() {