common: update Errors type (#1129)

* common: adjust common error slice to allow multi errors.Is matching and conform to interface better

* zb: forgot to save?

* linties: fixies

* linties: word change as well.

* nitters: glorious

* buts

* nitters: fix glorious bug

* Update common/common.go

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>

* nitters: shifty

---------

Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
Co-authored-by: Scott <gloriousCode@users.noreply.github.com>
This commit is contained in:
Ryan O'Hara-Reid
2023-02-20 10:48:24 +11:00
committed by GitHub
parent ffea386f81
commit d2561402c4
28 changed files with 325 additions and 270 deletions

View File

@@ -372,15 +372,15 @@ func (k *Kraken) GetTrades(ctx context.Context, symbol currency.Pair) ([]RecentT
}
if len(data.Error) > 0 {
var errs common.Errors
var errs error
for x := range data.Error {
errString, ok := data.Error[x].(string)
if !ok {
continue
}
errs = append(errs, errors.New(errString))
errs = common.AppendError(errs, errors.New(errString))
}
if len(errs) > 0 {
if errs != nil {
return nil, errs
}
}

View File

@@ -1264,13 +1264,13 @@ channels:
*s = append(*s, outbound)
}
var errs common.Errors
var errs error
for subType, subs := range subscriptions {
for i := range *subs {
if common.StringDataContains(authenticatedChannels, (*subs)[i].Subscription.Name) {
_, err := k.Websocket.AuthConn.SendMessageReturnResponse((*subs)[i].RequestID, (*subs)[i])
if err != nil {
errs = append(errs, err)
errs = common.AppendError(errs, err)
continue
}
k.Websocket.AddSuccessfulSubscriptions((*subs)[i].Channels...)
@@ -1285,16 +1285,13 @@ channels:
}
_, err := k.Websocket.Conn.SendMessageReturnResponse((*subs)[i].RequestID, (*subs)[i])
if err != nil {
errs = append(errs, err)
errs = common.AppendError(errs, err)
continue
}
k.Websocket.AddSuccessfulSubscriptions((*subs)[i].Channels...)
}
}
if errs != nil {
return errs
}
return nil
return errs
}
// Unsubscribe sends a websocket message to stop receiving data from the channel
@@ -1339,12 +1336,12 @@ channels:
unsubs = append(unsubs, unsub)
}
var errs common.Errors
var errs error
for i := range unsubs {
if common.StringDataContains(authenticatedChannels, unsubs[i].Subscription.Name) {
_, err := k.Websocket.AuthConn.SendMessageReturnResponse(unsubs[i].RequestID, unsubs[i])
if err != nil {
errs = append(errs, err)
errs = common.AppendError(errs, err)
continue
}
k.Websocket.RemoveSuccessfulUnsubscriptions(unsubs[i].Channels...)
@@ -1353,15 +1350,12 @@ channels:
_, err := k.Websocket.Conn.SendMessageReturnResponse(unsubs[i].RequestID, unsubs[i])
if err != nil {
errs = append(errs, err)
errs = common.AppendError(errs, err)
continue
}
k.Websocket.RemoveSuccessfulUnsubscriptions(unsubs[i].Channels...)
}
if errs != nil {
return errs
}
return nil
return errs
}
// wsAddOrder creates an order, returned order ID if success