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:
parent
3d7371a09c
commit
1d78b962af
1 changed files with 26 additions and 6 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue