1
0
Fork 0
mirror of https://github.com/arangodb/kube-arangodb.git synced 2024-12-15 17:51:03 +00:00

Updated go-driver

This commit is contained in:
Ewout Prangsma 2018-04-27 11:16:58 +02:00
parent 3d7371a09c
commit 1d78b962af
No known key found for this signature in database
GPG key ID: 4DBAD380D93D0698

View file

@ -143,11 +143,13 @@ func (c *agencyConnection) doOnce(ctx context.Context, req driver.Request) (driv
epReq := req.Clone()
result, err := epConn.Do(ctx, epReq)
if err == nil {
// Success
results <- result
// Cancel all other requests
cancel()
return
if err = isSuccess(result); err == nil {
// Success
results <- result
// Cancel all other requests
cancel()
return
}
}
// Check error
if statusCode, ok := isArangoError(err); ok {
@ -160,6 +162,10 @@ func (c *agencyConnection) doOnce(ctx context.Context, req driver.Request) (driv
return
}
}
// No permanent error. Are we the only endpoint?
if len(connections) == 1 {
errors <- driver.WithStack(err)
}
// No permanent error, try next agent
}(epConn)
}
@ -180,6 +186,20 @@ func (c *agencyConnection) doOnce(ctx context.Context, req driver.Request) (driv
return nil, false, driver.WithStack(fmt.Errorf("All %d servers responded with temporary failure", len(connections)))
}
func isSuccess(resp driver.Response) error {
if resp == nil {
return driver.WithStack(fmt.Errorf("Response is nil"))
}
statusCode := resp.StatusCode()
if statusCode >= 200 && statusCode < 300 {
return nil
}
return driver.ArangoError{
HasError: true,
Code: statusCode,
}
}
// isArangoError checks if the given error is (or is caused by) an ArangoError.
// If so it returned the Code and true, otherwise it returns 0, false.
func isArangoError(err error) (int, bool) {
@ -224,7 +244,7 @@ func (c *agencyConnection) UpdateEndpoints(endpoints []string) error {
for i, ep := range endpoints {
config := c.config
config.Endpoints = []string{ep}
config.FailOnRedirect = true
config.DontFollowRedirect = true
httpConn, err := http.NewConnection(config)
if err != nil {
return driver.WithStack(err)