attach the grootAccessJWT to the request and sends the http request
(req *http.Request)
| 286 | |
| 287 | // attach the grootAccessJWT to the request and sends the http request |
| 288 | func runRequest(req *http.Request) (*x.QueryResWithData, []byte, *http.Response, error) { |
| 289 | client := &http.Client{} |
| 290 | req.Header.Set("X-Dgraph-AccessToken", token.getAccessJWTToken()) |
| 291 | resp, err := client.Do(req) |
| 292 | if err != nil { |
| 293 | return nil, nil, resp, err |
| 294 | } |
| 295 | if status := resp.StatusCode; status != http.StatusOK { |
| 296 | return nil, nil, resp, errors.Errorf("Unexpected status code: %v", status) |
| 297 | } |
| 298 | |
| 299 | defer resp.Body.Close() |
| 300 | body, err := io.ReadAll(resp.Body) |
| 301 | if err != nil { |
| 302 | return nil, nil, resp, errors.Errorf("unable to read from body: %v", err) |
| 303 | } |
| 304 | |
| 305 | qr := new(x.QueryResWithData) |
| 306 | _ = json.Unmarshal(body, qr) // Don't check error. |
| 307 | if len(qr.Errors) > 0 { |
| 308 | return nil, nil, resp, errors.New(qr.Errors[0].Message) |
| 309 | } |
| 310 | return qr, body, resp, nil |
| 311 | } |
| 312 | |
| 313 | func runWithRetriesForResp(method, contentType, url string, body string) ( |
| 314 | *x.QueryResWithData, []byte, *http.Response, error) { |
no test coverage detected