Return error for notify
This commit is contained in:
parent
4f9788a158
commit
42cb6446b9
|
@ -376,6 +376,25 @@ func makeJSONResponse(err error) *C.char {
|
||||||
// Notify sends push notification by given token
|
// Notify sends push notification by given token
|
||||||
//export Notify
|
//export Notify
|
||||||
func Notify(token *C.char) *C.char {
|
func Notify(token *C.char) *C.char {
|
||||||
res := statusAPI.Notify(C.GoString(token))
|
err := statusAPI.Notify(C.GoString(token))
|
||||||
return C.CString(res)
|
|
||||||
|
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))
|
||||||
}
|
}
|
||||||
|
|
|
@ -195,7 +195,7 @@ func (api *StatusAPI) JailBaseJS(js string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify and send message.
|
// Notify and send message.
|
||||||
func (api *StatusAPI) Notify(token string) string {
|
func (api *StatusAPI) Notify(token string) error {
|
||||||
log.Debug("Notify", "token", token)
|
log.Debug("Notify", "token", token)
|
||||||
|
|
||||||
// TODO(oskarth): Experiment with this
|
// TODO(oskarth): Experiment with this
|
||||||
|
@ -204,10 +204,10 @@ func (api *StatusAPI) Notify(token string) string {
|
||||||
"sum": "Happy Day",
|
"sum": "Happy Day",
|
||||||
}
|
}
|
||||||
|
|
||||||
err := api.b.notification.Notify(msg, token)
|
err := api.b.notifier().Notify(msg, token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Notify failed:", err)
|
log.Error("Notify failed:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return token
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ type StatusBackend struct {
|
||||||
accountManager common.AccountManager
|
accountManager common.AccountManager
|
||||||
txQueueManager common.TxQueueManager
|
txQueueManager common.TxQueueManager
|
||||||
jailManager common.JailManager
|
jailManager common.JailManager
|
||||||
notification common.Notifier
|
notifier common.NotifierConstructor
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewStatusBackend create a new NewStatusBackend instance
|
// NewStatusBackend create a new NewStatusBackend instance
|
||||||
|
@ -47,7 +47,7 @@ func NewStatusBackend() *StatusBackend {
|
||||||
accountManager: accountManager,
|
accountManager: accountManager,
|
||||||
jailManager: jailManager,
|
jailManager: jailManager,
|
||||||
txQueueManager: txQueueManager,
|
txQueueManager: txQueueManager,
|
||||||
notification: notificationManager,
|
notifier: notificationManager,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,3 +4,6 @@ package common
|
||||||
type Notifier interface {
|
type Notifier interface {
|
||||||
Notify(body interface{}, tokens ...string) error
|
Notify(body interface{}, tokens ...string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NotifierConstructor returns constructor of configured instance Notifier interface.
|
||||||
|
type NotifierConstructor func() Notifier
|
||||||
|
|
|
@ -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
|
// LoadTestConfig loads test configuration values from disk
|
||||||
func LoadTestConfig() (*TestConfig, error) {
|
func LoadTestConfig() (*TestConfig, error) {
|
||||||
var testConfig TestConfig
|
var testConfig TestConfig
|
||||||
|
|
Loading…
Reference in New Issue