Skip to content

Commit 1d78b96

Browse files
committed
Updated go-driver
1 parent 3d7371a commit 1d78b96

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

deps/github.com/arangodb/go-driver/agency/agency_connection.go

+26-6
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,13 @@ func (c *agencyConnection) doOnce(ctx context.Context, req driver.Request) (driv
143143
epReq := req.Clone()
144144
result, err := epConn.Do(ctx, epReq)
145145
if err == nil {
146-
// Success
147-
results <- result
148-
// Cancel all other requests
149-
cancel()
150-
return
146+
if err = isSuccess(result); err == nil {
147+
// Success
148+
results <- result
149+
// Cancel all other requests
150+
cancel()
151+
return
152+
}
151153
}
152154
// Check error
153155
if statusCode, ok := isArangoError(err); ok {
@@ -160,6 +162,10 @@ func (c *agencyConnection) doOnce(ctx context.Context, req driver.Request) (driv
160162
return
161163
}
162164
}
165+
// No permanent error. Are we the only endpoint?
166+
if len(connections) == 1 {
167+
errors <- driver.WithStack(err)
168+
}
163169
// No permanent error, try next agent
164170
}(epConn)
165171
}
@@ -180,6 +186,20 @@ func (c *agencyConnection) doOnce(ctx context.Context, req driver.Request) (driv
180186
return nil, false, driver.WithStack(fmt.Errorf("All %d servers responded with temporary failure", len(connections)))
181187
}
182188

189+
func isSuccess(resp driver.Response) error {
190+
if resp == nil {
191+
return driver.WithStack(fmt.Errorf("Response is nil"))
192+
}
193+
statusCode := resp.StatusCode()
194+
if statusCode >= 200 && statusCode < 300 {
195+
return nil
196+
}
197+
return driver.ArangoError{
198+
HasError: true,
199+
Code: statusCode,
200+
}
201+
}
202+
183203
// isArangoError checks if the given error is (or is caused by) an ArangoError.
184204
// If so it returned the Code and true, otherwise it returns 0, false.
185205
func isArangoError(err error) (int, bool) {
@@ -224,7 +244,7 @@ func (c *agencyConnection) UpdateEndpoints(endpoints []string) error {
224244
for i, ep := range endpoints {
225245
config := c.config
226246
config.Endpoints = []string{ep}
227-
config.FailOnRedirect = true
247+
config.DontFollowRedirect = true
228248
httpConn, err := http.NewConnection(config)
229249
if err != nil {
230250
return driver.WithStack(err)

0 commit comments

Comments
 (0)