diff --git a/src/App.vue b/src/App.vue index aef4d09..fc901d5 100644 --- a/src/App.vue +++ b/src/App.vue @@ -99,18 +99,15 @@ export default { } else { const startAt = Date.now(); fetchCommands(this.$store.state.clientID, this.$store.state.token.value, this.$store.state.proxyURL, this.$store.state.selectedGuildID).then((commands) => { - if (!commands) { + setTimeout(() => { + this.$store.commit('SET_COMMANDS', commands); this.loading = false; - this.missingScope = true; - } else { - setTimeout(() => { - this.$store.commit('SET_COMMANDS', commands); - this.loading = false; - }, (Date.now() - startAt) + 100); - } - }).catch(() => { + }, (Date.now() - startAt) + 100); + }).catch((err) => { + console.log(err.statusCode); this.loading = false; - this.$router.push('/settings'); + if (err.statusCode === 403) this.missingScope = true; + else this.$router.push('/settings'); }); } } diff --git a/src/api.js b/src/api.js index 94b6493..3bf332d 100644 --- a/src/api.js +++ b/src/api.js @@ -3,7 +3,7 @@ import axios from 'axios'; const getURL = (clientID, guildID, commandID) => `applications/${clientID}/${guildID ? `guilds/${guildID}/` : ''}${commandID ? `commands/${commandID}` : 'commands'}`; export function request (token, proxyURL, url, method, data) { - return new Promise((resolve) => { + return new Promise((resolve, reject) => { axios({ url: `${proxyURL}/https://discord.com/api/v8/${url}`, method, @@ -14,8 +14,8 @@ export function request (token, proxyURL, url, method, data) { } }).then((value) => { resolve(value.data); - }).catch(() => { - resolve(null); + }).catch((err) => { + reject(err); }); }); } @@ -28,7 +28,7 @@ export function request (token, proxyURL, url, method, data) { * @returns {Promise} */ export function getToken (clientID, clientSecret, proxyURL) { - return new Promise((resolve) => { + return new Promise((resolve, reject) => { const data = new URLSearchParams(); data.append('grant_type', 'client_credentials'); data.append('scope', 'applications.commands.update'); @@ -42,8 +42,8 @@ export function getToken (clientID, clientSecret, proxyURL) { } }).then((value) => { resolve(value.data); - }).catch(() => { - resolve(null); + }).catch((err) => { + reject(err); }); }); } diff --git a/src/views/Settings.vue b/src/views/Settings.vue index 6606e04..8e8a422 100644 --- a/src/views/Settings.vue +++ b/src/views/Settings.vue @@ -181,27 +181,23 @@ export default { proxyURL: this.proxyURL }); getToken(this.clientID, this.clientSecret, this.proxyURL).then((tokenData) => { - if (!tokenData) { - this.invalidClientCredentials.add(`${this.clientID}${this.clientSecret}`); - this.loading = false; - } else { - this.$store.dispatch('saveToken', { - expiresAt: Date.now() + (tokenData.expires_in * 1000), - value: tokenData.access_token + this.$store.dispatch('saveToken', { + expiresAt: Date.now() + (tokenData.expires_in * 1000), + value: tokenData.access_token + }); + fetchApplication(this.$store.state.clientID).then((application) => { + this.$toast.success(`Successfully logged in as ${application.username}!`, { + duration: 10000, + pauseOnHover: true }); - fetchApplication(this.$store.state.clientID).then((application) => { - this.$toast.success(`Successfully logged in as ${application.username}!`, { - duration: 10000, - pauseOnHover: true - }); - this.$router.push('/'); - }); - this.loading = false; - this.$root.loadCommands(); - } - }).catch(() => { + this.$router.push('/'); + }); + this.loading = false; + this.$root.loadCommands(); + }).catch((err) => { this.loading = false; - this.invalidProxyURLs.add(this.proxyURL); + if (!err.response) this.invalidProxyURLs.add(this.proxyURL); + else this.invalidClientCredentials.add(`${this.clientID}${this.clientSecret}`); }); } }