-
Notifications
You must be signed in to change notification settings - Fork 0
/
exchange_error.go
41 lines (33 loc) · 1.15 KB
/
exchange_error.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package price_function
import (
"fmt"
"github.com/jinxprotocol/v4-chain/protocol/daemons/pricefeed/client/types"
)
// ExchangeError describes an error that is specific to a particular exchange. These errors are emitted
// by an exchange's price function whenever the exchange's API returns a valid http response.
type ExchangeError interface {
error
GetExchangeId() types.ExchangeId
}
// Ensure ExcahngeErrorImpl implements ExchangeError at compile time.
var _ ExchangeError = &ExchangeErrorImpl{}
// ExchangeErrorImpl implements ExchangeError.
type ExchangeErrorImpl struct {
exchangeId types.ExchangeId
err error
}
// Error returns a string representation of the error.
func (e *ExchangeErrorImpl) Error() string {
return fmt.Sprintf("%v exchange error: %v", e.exchangeId, e.err)
}
// GetExchangeId returns the exchange id associated with the error.
func (e *ExchangeErrorImpl) GetExchangeId() types.ExchangeId {
return e.exchangeId
}
// NewExchangeError returns a new ExchangeError.
func NewExchangeError(exchangeId types.ExchangeId, msg string) ExchangeError {
return &ExchangeErrorImpl{
exchangeId: exchangeId,
err: fmt.Errorf(msg),
}
}