MCPcopy Create free account
hub / github.com/UiPath/uipathcli / sendWithRetries

Method sendWithRetries

utils/network/http_client.go:38–78  ·  view source on GitHub ↗
(request *HttpRequest, ctx context.Context)

Source from the content-addressed store, hash-verified

36}
37
38func (c HttpClient) sendWithRetries(request *HttpRequest, ctx context.Context) (*HttpResponse, error) {
39 request.Header.Set("User-Agent", UserAgent)
40 request.Header.Set("x-request-id", c.settings.OperationId)
41 if request.Authorization != nil {
42 request.Header.Set("Authorization", fmt.Sprintf("%s %s", request.Authorization.Type, request.Authorization.Value))
43 }
44
45 if c.settings.Debug {
46 request.Body = newResettableReader(request.Body, bufferLimit, func(body []byte) { c.logRequest(request, body) })
47 } else if c.settings.MaxAttempts > 1 {
48 request.Body = newResettableReader(request.Body, bufferLimit, func(body []byte) {})
49 }
50
51 var response *HttpResponse
52 var err error
53 err = resiliency.RetryN(c.settings.MaxAttempts, func(attempt int) error {
54 if attempt > 1 && !c.resetReader(request.Body) {
55 return err
56 }
57
58 response, err = c.send(request, ctx)
59 if err != nil {
60 return resiliency.Retryable(err)
61 }
62
63 if c.settings.Debug {
64 response.Body = newResettableReader(response.Body, bufferLimit, func(body []byte) { c.logResponse(response, body) })
65 }
66
67 if response.StatusCode == 0 || response.StatusCode >= 500 {
68 defer func() { _ = response.Body.Close() }()
69 body, err := io.ReadAll(response.Body)
70 if err != nil {
71 return resiliency.Retryable(fmt.Errorf("Error reading response: %w", err))
72 }
73 return resiliency.Retryable(fmt.Errorf("Service returned status code '%v' and body '%v'", response.StatusCode, string(body)))
74 }
75 return nil
76 })
77 return response, err
78}
79
80func (c HttpClient) resetReader(reader io.Reader) bool {
81 resettableReader, ok := reader.(*resettableReader)

Callers 2

SendMethod · 0.95
SendWithContextMethod · 0.95

Calls 9

logRequestMethod · 0.95
resetReaderMethod · 0.95
sendMethod · 0.95
logResponseMethod · 0.95
RetryNFunction · 0.92
RetryableFunction · 0.92
newResettableReaderFunction · 0.85
CloseMethod · 0.80
SetMethod · 0.65

Tested by

no test coverage detected