Add error to login signal (#1594)

We add an error to login signal so that the caller can tell whether
login was successful or not
This commit is contained in:
Andrea Maria Piana 2019-09-03 15:00:14 +02:00 committed by GitHub
parent 4ef35fa1bc
commit 42199e682f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 4 deletions

View File

@ -237,7 +237,7 @@ func (b *StatusBackend) StartNodeWithKey(acc multiaccounts.Account, password str
return b.injectAccountIntoServices()
}
func (b *StatusBackend) StartNodeWithAccount(acc multiaccounts.Account, password string) error {
func (b *StatusBackend) startNodeWithAccount(acc multiaccounts.Account, password string) error {
err := b.ensureAppDBOpened(acc, password)
if err != nil {
return err
@ -280,10 +280,19 @@ func (b *StatusBackend) StartNodeWithAccount(acc multiaccounts.Account, password
if err != nil {
return err
}
signal.SendLoggedIn()
return nil
}
func (b *StatusBackend) StartNodeWithAccount(acc multiaccounts.Account, password string) error {
err := b.startNodeWithAccount(acc, password)
signal.SendLoggedIn(err)
if err != nil {
// Stop node for clean up
_ = b.StopNode()
}
return err
}
// StartNodeWithAccountAndConfig is used after account and config was generated.
// In current setup account name and config is generated on the client side. Once/if it will be generated on
// status-go side this flow can be simplified.

View File

@ -26,6 +26,11 @@ type NodeCrashEvent struct {
Error string `json:"error"`
}
// NodeLoginEvent returns the result of the login event
type NodeLoginEvent struct {
Error string `json:"error,omitempty"`
}
// SendNodeCrashed emits a signal when status node has crashed, and
// provides error description.
func SendNodeCrashed(err error) {
@ -57,6 +62,10 @@ func SendChainDataRemoved() {
send(EventChainDataRemoved, nil)
}
func SendLoggedIn() {
send(EventLoggedIn, nil)
func SendLoggedIn(err error) {
event := NodeLoginEvent{}
if err != nil {
event.Error = err.Error()
}
send(EventLoggedIn, event)
}