@@ -143,11 +143,13 @@ func (c *agencyConnection) doOnce(ctx context.Context, req driver.Request) (driv
143
143
epReq := req .Clone ()
144
144
result , err := epConn .Do (ctx , epReq )
145
145
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
+ }
151
153
}
152
154
// Check error
153
155
if statusCode , ok := isArangoError (err ); ok {
@@ -160,6 +162,10 @@ func (c *agencyConnection) doOnce(ctx context.Context, req driver.Request) (driv
160
162
return
161
163
}
162
164
}
165
+ // No permanent error. Are we the only endpoint?
166
+ if len (connections ) == 1 {
167
+ errors <- driver .WithStack (err )
168
+ }
163
169
// No permanent error, try next agent
164
170
}(epConn )
165
171
}
@@ -180,6 +186,20 @@ func (c *agencyConnection) doOnce(ctx context.Context, req driver.Request) (driv
180
186
return nil , false , driver .WithStack (fmt .Errorf ("All %d servers responded with temporary failure" , len (connections )))
181
187
}
182
188
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
+
183
203
// isArangoError checks if the given error is (or is caused by) an ArangoError.
184
204
// If so it returned the Code and true, otherwise it returns 0, false.
185
205
func isArangoError (err error ) (int , bool ) {
@@ -224,7 +244,7 @@ func (c *agencyConnection) UpdateEndpoints(endpoints []string) error {
224
244
for i , ep := range endpoints {
225
245
config := c .config
226
246
config .Endpoints = []string {ep }
227
- config .FailOnRedirect = true
247
+ config .DontFollowRedirect = true
228
248
httpConn , err := http .NewConnection (config )
229
249
if err != nil {
230
250
return driver .WithStack (err )
0 commit comments