@@ -4,12 +4,12 @@ import (
44 "io"
55 "log"
66 "net/http"
7- "time"
87
98 "github.com/appbaseio/arc/model/acl"
109 "github.com/appbaseio/arc/model/category"
1110 "github.com/appbaseio/arc/model/op"
1211 "github.com/appbaseio/arc/util"
12+ "github.com/hashicorp/go-retryablehttp"
1313)
1414
1515func (es * elasticsearch ) handler () http.HandlerFunc {
@@ -37,21 +37,22 @@ func (es *elasticsearch) handler() http.HandlerFunc {
3737 return
3838 }
3939 log .Printf (`%s: category="%s", acl="%s", op="%s"\n` , logTag , * reqCategory , * reqACL , * reqOp )
40-
4140 // Forward the request to elasticsearch
42- client := util . HTTPClient ()
41+ client := retryablehttp . NewClient ()
4342
44- var response * http.Response
45- util .Retry (3 , 100 * time .Millisecond , func () bool {
46- response , err = client .Do (r )
47- if err != nil {
48- log .Printf ("%s: error fetching response for %s: %v\n " , logTag , r .URL .Path , err )
49- util .WriteBackError (w , err .Error (), http .StatusInternalServerError )
50- return false
51- }
52- err = nil
53- return true
54- })
43+ request , err := retryablehttp .FromRequest (r )
44+ if err != nil {
45+ log .Printf ("%s: error while converting to retryable request for %s: %v\n " , logTag , r .URL .Path , err )
46+ util .WriteBackError (w , err .Error (), http .StatusInternalServerError )
47+ return
48+ }
49+ response , err := client .Do (request )
50+
51+ if err != nil {
52+ log .Printf ("%s: error fetching response for %s: %v\n " , logTag , r .URL .Path , err )
53+ util .WriteBackError (w , err .Error (), http .StatusInternalServerError )
54+ return
55+ }
5556
5657 defer response .Body .Close ()
5758
0 commit comments