Merge pull request #43 from h3poteto/iss-16

closes #16 Error message when api call has error
This commit is contained in:
AkiraFukushima 2018-03-13 22:35:40 +09:00 committed by GitHub
commit 675ddabc83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 63 additions and 42 deletions

6
package-lock.json generated
View File

@ -493,9 +493,9 @@
"integrity": "sha1-g+9cqGCysy5KDe7e6MdxudtXRx4=" "integrity": "sha1-g+9cqGCysy5KDe7e6MdxudtXRx4="
}, },
"axios": { "axios": {
"version": "0.16.2", "version": "0.18.0",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.16.2.tgz", "resolved": "https://registry.npmjs.org/axios/-/axios-0.18.0.tgz",
"integrity": "sha1-uk+S8XFn37q0CYN4VFS5rBScPG0=", "integrity": "sha1-MtU+SFHv3AoRmTts0AB4nXDAUQI=",
"requires": { "requires": {
"follow-redirects": "1.4.1", "follow-redirects": "1.4.1",
"is-buffer": "1.1.6" "is-buffer": "1.1.6"

View File

@ -56,7 +56,7 @@
} }
}, },
"dependencies": { "dependencies": {
"axios": "^0.16.1", "axios": "^0.18.0",
"element-ui": "^2.2.1", "element-ui": "^2.2.1",
"google-fonts-webpack-plugin": "^0.4.4", "google-fonts-webpack-plugin": "^0.4.4",
"is-empty": "^1.2.0", "is-empty": "^1.2.0",

View File

@ -27,6 +27,12 @@ export default {
.then((id) => { .then((id) => {
this.$router.push({ path: `/${id}/home` }) this.$router.push({ path: `/${id}/home` })
}) })
.catch(() => {
this.$message({
message: 'Could not authorize the code',
type: 'error'
})
})
} }
} }
} }

View File

@ -19,9 +19,33 @@ export default {
this.$store.dispatch('TimelineSpace/fetchAccount', this.$route.params.id) this.$store.dispatch('TimelineSpace/fetchAccount', this.$route.params.id)
.then((account) => { .then((account) => {
this.$store.dispatch('TimelineSpace/fetchHomeTimeline', account) this.$store.dispatch('TimelineSpace/fetchHomeTimeline', account)
.catch(() => {
this.$message({
message: 'Could not fetch timeline',
type: 'error'
})
})
this.$store.dispatch('TimelineSpace/startUserStreaming', account) this.$store.dispatch('TimelineSpace/startUserStreaming', account)
.catch(() => {
this.$message({
message: 'Could not start user streaming',
type: 'error'
})
})
this.$store.dispatch('TimelineSpace/username', account) this.$store.dispatch('TimelineSpace/username', account)
.catch(() => {
this.$message({
message: 'Could not fetch username',
type: 'error'
})
})
this.$store.dispatch('TimelineSpace/fetchNotifications', account) this.$store.dispatch('TimelineSpace/fetchNotifications', account)
.catch(() => {
this.$message({
message: 'Could not fetch notification',
type: 'error'
})
})
this.$store.dispatch('TimelineSpace/watchShortcutEvents', account) this.$store.dispatch('TimelineSpace/watchShortcutEvents', account)
}) })
.catch(() => { .catch(() => {

View File

@ -9,11 +9,10 @@ const Authorize = {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
ipcRenderer.send('get-access-token', code) ipcRenderer.send('get-access-token', code)
ipcRenderer.once('response-get-access-token', (event, id) => { ipcRenderer.once('response-get-access-token', (event, id) => {
console.log(id)
resolve(id) resolve(id)
}) })
ipcRenderer.once('error-get-access-token', (event, err) => { ipcRenderer.once('error-get-access-token', (event, err) => {
console.log(err) reject(err)
}) })
}) })
} }

View File

@ -46,8 +46,6 @@ const TimelineSpace = {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
ipcRenderer.send('get-local-account', id) ipcRenderer.send('get-local-account', id)
ipcRenderer.once('error-get-local-account', (event, err) => { ipcRenderer.once('error-get-local-account', (event, err) => {
// TODO: handle error
console.log(err)
reject(err) reject(err)
}) })
ipcRenderer.once('response-get-local-account', (event, account) => { ipcRenderer.once('response-get-local-account', (event, account) => {
@ -63,18 +61,14 @@ const TimelineSpace = {
access_token: account.accessToken, access_token: account.accessToken,
api_url: account.baseURL + '/api/v1' api_url: account.baseURL + '/api/v1'
}) })
client.get('/accounts/verify_credentials', {}) client.get('/accounts/verify_credentials', (err, data, res) => {
.then((res) => { if (err) return reject(err)
commit('updateUsername', res.data.username) commit('updateUsername', data.username)
resolve(res) resolve(res)
}) })
}) })
}, },
startUserStreaming ({ commit }, account) { startUserStreaming ({ commit }, account) {
ipcRenderer.send('start-user-streaming', account)
ipcRenderer.once('error-start-userstreaming', (event, err) => {
console.log(err)
})
ipcRenderer.on('update-start-user-streaming', (event, update) => { ipcRenderer.on('update-start-user-streaming', (event, update) => {
commit('appendHomeTimeline', update) commit('appendHomeTimeline', update)
}) })
@ -85,6 +79,13 @@ const TimelineSpace = {
} }
commit('appendNotifications', notification) commit('appendNotifications', notification)
}) })
return new Promise((resolve, reject) => {
ipcRenderer.send('start-user-streaming', account)
ipcRenderer.once('error-start-userstreaming', (event, err) => {
reject(err)
})
})
}, },
stopUserStreaming ({ commit }) { stopUserStreaming ({ commit }) {
ipcRenderer.send('stop-user-streaming') ipcRenderer.send('stop-user-streaming')
@ -94,6 +95,7 @@ const TimelineSpace = {
commit('changeNewTootModal', true) commit('changeNewTootModal', true)
}) })
ipcRenderer.on('CmdOrCtrl+R', () => { ipcRenderer.on('CmdOrCtrl+R', () => {
// TODO: reply window
console.log('reply') console.log('reply')
}) })
}, },
@ -105,14 +107,11 @@ const TimelineSpace = {
api_url: account.baseURL + '/api/v1' api_url: account.baseURL + '/api/v1'
} }
) )
client.get('/timelines/home', { limit: 40 }) client.get('/timelines/home', { limit: 40 }, (err, data, res) => {
.then((res) => { if (err) return reject(err)
commit('insertHomeTimeline', res.data) commit('insertHomeTimeline', data)
resolve() resolve(res)
}) })
.catch((err) => {
reject(err)
})
}) })
}, },
fetchNotifications ({ commit }, account) { fetchNotifications ({ commit }, account) {
@ -123,14 +122,11 @@ const TimelineSpace = {
api_url: account.baseURL + '/api/v1' api_url: account.baseURL + '/api/v1'
} }
) )
client.get('/notifications', { limit: 30 }) client.get('/notifications', { limit: 30 }, (err, data, res) => {
.then((res) => { if (err) return reject(err)
commit('insertNotifications', res.data) commit('insertNotifications', data)
resolve() resolve(res)
}) })
.catch((err) => {
reject(err)
})
}) })
}, },
postToot ({ commit, state }, body) { postToot ({ commit, state }, body) {
@ -146,14 +142,11 @@ const TimelineSpace = {
) )
client.post('/statuses', { client.post('/statuses', {
status: body status: body
}, (err, data, res) => {
if (err) return reject(err)
commit('changeNewTootModal', false)
resolve(res)
}) })
.then((res) => {
commit('changeNewTootModal', false)
resolve(res)
})
.catch((err) => {
reject(err)
})
}) })
} }
} }
@ -161,8 +154,7 @@ const TimelineSpace = {
export default TimelineSpace export default TimelineSpace
class AuthenticationError { class AuthenticationError {}
}
function buildNotification (notification) { function buildNotification (notification) {
switch (notification.type) { switch (notification.type) {