Add error handling of login-complete
This commit is contained in:
parent
7359995a3e
commit
78d87633f5
|
@ -63,7 +63,11 @@ export default class AccountAuth extends Vue {
|
||||||
public authCode() {
|
public authCode() {
|
||||||
ipcRenderer.once(
|
ipcRenderer.once(
|
||||||
`login-complete`,
|
`login-complete`,
|
||||||
(e: Event, account: Account) => {
|
(e: Event, account?: Account, error?: Error) => {
|
||||||
|
if (error != undefined || account === undefined) {
|
||||||
|
console.error(error)
|
||||||
|
return
|
||||||
|
}
|
||||||
this.$emit('login-complete', account)
|
this.$emit('login-complete', account)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -78,19 +78,15 @@ export default class Auth {
|
||||||
tokenData = await Mastodon.fetchAccessToken(clientId, clientSecret, code, "https://" + instance, redirectUri)
|
tokenData = await Mastodon.fetchAccessToken(clientId, clientSecret, code, "https://" + instance, redirectUri)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
let error: Error = err
|
let error: Error = err
|
||||||
event.sender.send(`error`, {
|
error.name = "ERROR_CONNECTION"
|
||||||
id: "ERROR_CONNECTION",
|
event.sender.send(`login-complete`, undefined, error)
|
||||||
message: "Connection error",
|
|
||||||
meta: error
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tokenData.accessToken === undefined) {
|
if (tokenData.accessToken === undefined) {
|
||||||
event.sender.send(`error`, {
|
let error = new Error("Failed to get access token.")
|
||||||
id: "ERROR_GET_TOKEN",
|
error.name = "ERROR_GET_TOKEN"
|
||||||
message: "Failed to get access token."
|
event.sender.send(`login-complete`, undefined, error)
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,11 +113,10 @@ export default class Auth {
|
||||||
let newDoc = await db.insert(docs)
|
let newDoc = await db.insert(docs)
|
||||||
Client.setAuthClient('http', newDoc.full, client)
|
Client.setAuthClient('http', newDoc.full, client)
|
||||||
event.sender.send(`login-complete`, newDoc)
|
event.sender.send(`login-complete`, newDoc)
|
||||||
} catch (error) {
|
} catch (err) {
|
||||||
event.sender.send(`error`, {
|
let error = new Error("You cannot login already logined account.")
|
||||||
id: "ERROR_YOU_TRY_ANOTHER_ACCOUNT",
|
error.name = "ERROR_YOU_TRY_ANOTHER_ACCOUNT"
|
||||||
message: "You cannot login already logined account."
|
event.sender.send(`login-complete`, undefined, error)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user