Return error for notify

This commit is contained in:
Eugene 2017-10-12 17:31:39 +03:00 committed by Evgeny Danienko
parent 4f9788a158
commit 42cb6446b9
No known key found for this signature in database
GPG Key ID: BC8C34D8B45BECBF
5 changed files with 35 additions and 7 deletions

View File

@ -376,6 +376,25 @@ func makeJSONResponse(err error) *C.char {
// Notify sends push notification by given token
//export Notify
func Notify(token *C.char) *C.char {
res := statusAPI.Notify(C.GoString(token))
return C.CString(res)
err := statusAPI.Notify(C.GoString(token))
res := true
errString := ""
if err != nil {
res = false
errString = err.Error()
}
out := common.NotifyResult{
Status: res,
Error: errString,
}
outBytes, err := json.Marshal(&out)
if err != nil {
log.Error("failed to marshal Notify output", "error", err.Error())
return makeJSONResponse(err)
}
return C.CString(string(outBytes))
}

View File

@ -195,7 +195,7 @@ func (api *StatusAPI) JailBaseJS(js string) {
}
// Notify and send message.
func (api *StatusAPI) Notify(token string) string {
func (api *StatusAPI) Notify(token string) error {
log.Debug("Notify", "token", token)
// TODO(oskarth): Experiment with this
@ -204,10 +204,10 @@ func (api *StatusAPI) Notify(token string) string {
"sum": "Happy Day",
}
err := api.b.notification.Notify(msg, token)
err := api.b.notifier().Notify(msg, token)
if err != nil {
log.Error("Notify failed:", err)
}
return token
return err
}

View File

@ -29,7 +29,7 @@ type StatusBackend struct {
accountManager common.AccountManager
txQueueManager common.TxQueueManager
jailManager common.JailManager
notification common.Notifier
notifier common.NotifierConstructor
}
// NewStatusBackend create a new NewStatusBackend instance
@ -47,7 +47,7 @@ func NewStatusBackend() *StatusBackend {
accountManager: accountManager,
jailManager: jailManager,
txQueueManager: txQueueManager,
notification: notificationManager,
notifier: notificationManager,
}
}

View File

@ -4,3 +4,6 @@ package common
type Notifier interface {
Notify(body interface{}, tokens ...string) error
}
// NotifierConstructor returns constructor of configured instance Notifier interface.
type NotifierConstructor func() Notifier

View File

@ -395,6 +395,12 @@ type TestConfig struct {
}
}
// NotifyResult is a JSON returned from notify message
type NotifyResult struct {
Status bool `json:"status"`
Error string `json:"error"`
}
// LoadTestConfig loads test configuration values from disk
func LoadTestConfig() (*TestConfig, error) {
var testConfig TestConfig