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="
},
"axios": {
"version": "0.16.2",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.16.2.tgz",
"integrity": "sha1-uk+S8XFn37q0CYN4VFS5rBScPG0=",
"version": "0.18.0",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.18.0.tgz",
"integrity": "sha1-MtU+SFHv3AoRmTts0AB4nXDAUQI=",
"requires": {
"follow-redirects": "1.4.1",
"is-buffer": "1.1.6"

View File

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

View File

@ -27,6 +27,12 @@ export default {
.then((id) => {
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)
.then((account) => {
this.$store.dispatch('TimelineSpace/fetchHomeTimeline', account)
.catch(() => {
this.$message({
message: 'Could not fetch timeline',
type: 'error'
})
})
this.$store.dispatch('TimelineSpace/startUserStreaming', account)
.catch(() => {
this.$message({
message: 'Could not start user streaming',
type: 'error'
})
})
this.$store.dispatch('TimelineSpace/username', account)
.catch(() => {
this.$message({
message: 'Could not fetch username',
type: 'error'
})
})
this.$store.dispatch('TimelineSpace/fetchNotifications', account)
.catch(() => {
this.$message({
message: 'Could not fetch notification',
type: 'error'
})
})
this.$store.dispatch('TimelineSpace/watchShortcutEvents', account)
})
.catch(() => {

View File

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