| 346 | } |
| 347 | |
| 348 | func (s *Session) get(ctx context.Context, uri string, out any) error { |
| 349 | req, err := http.NewRequestWithContext(ctx, "GET", uri, nil) |
| 350 | if err != nil { |
| 351 | return err |
| 352 | } |
| 353 | if req.URL, err = url.Parse(uri); err != nil { |
| 354 | return err |
| 355 | } |
| 356 | req.Header.Set("Content-Type", "application/json") |
| 357 | |
| 358 | res, err := s.Do(req) |
| 359 | if err != nil { |
| 360 | return err |
| 361 | } |
| 362 | if res.StatusCode != http.StatusOK { |
| 363 | var errorsRes *Error |
| 364 | if err = json.NewDecoder(res.Body).Decode(&errorsRes); err != nil { |
| 365 | return err |
| 366 | } |
| 367 | requestId := res.Header.Get("X-Request-Id") |
| 368 | return fmt.Errorf("request [%s]: %w: %s", requestId, StatusCodeError(res.StatusCode), errorsRes.Title) |
| 369 | } |
| 370 | return json.NewDecoder(res.Body).Decode(out) |
| 371 | } |
| 372 | |
| 373 | func (s *Session) post(ctx context.Context, path string, in, out any) error { |
| 374 | var buf bytes.Buffer |