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
Tim Raymond 2016-09-19 10:09:53 -04:00
parent 536fa7de8f
commit aacc6180d3
4 changed files with 16 additions and 16 deletions

13
errors.go Normal file
View File

@ -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)
}

View File

@ -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
}

View File

@ -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
}
}

View File

@ -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)
}
}