Rework domain errs to be strings
At @goller's recommendation, we're following @benbjohnson's advice laid out here: https://github.com/benbjohnson/wtf/blob/master/errors.go and moving errors to the top level package. This cleaned up some ugliness in the tests where we needed to type assert.pull/53/head
parent
536fa7de8f
commit
aacc6180d3
|
@ -0,0 +1,13 @@
|
|||
package mrfusion
|
||||
|
||||
// General errors.
|
||||
const (
|
||||
ErrUpstreamTimeout = Error("request to backend timed out")
|
||||
)
|
||||
|
||||
// Error is a domain error encountered while processing mrfusion requests
|
||||
type Error string
|
||||
|
||||
func (e Error) Error() string {
|
||||
return string(e)
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package influx
|
||||
|
||||
const (
|
||||
ErrTimedOut string = "Timeout during request to InfluxDB"
|
||||
)
|
||||
|
||||
// TimeoutError is returned when requests to InfluxDB are cancelled or time
|
||||
// out.
|
||||
type TimeoutError struct{}
|
||||
|
||||
func (te TimeoutError) Error() string {
|
||||
return ErrTimedOut
|
||||
}
|
|
@ -45,7 +45,7 @@ func (c *Client) Query(ctx context.Context, query mrfusion.Query) (mrfusion.Resp
|
|||
case resp := <-resps:
|
||||
return resp, resp.err
|
||||
case <-ctx.Done():
|
||||
return nil, TimeoutError{}
|
||||
return nil, mrfusion.ErrUpstreamTimeout
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ func Test_Influx_CancelsInFlightRequests(t *testing.T) {
|
|||
}
|
||||
|
||||
err := <-errs
|
||||
if _, ok := err.(influx.TimeoutError); !ok {
|
||||
t.Error("Expected TimeoutError but wasn't. err was", err)
|
||||
if err != mrfusion.ErrUpstreamTimeout {
|
||||
t.Error("Expected timeout error but wasn't. err was", err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue