(ctx context.Context, method, path string, body interface{})
| 19 | } |
| 20 | |
| 21 | func (r *consumeRuntime) CallAPI(ctx context.Context, method, path string, body interface{}) (json.RawMessage, error) { |
| 22 | resp, err := r.client.DoAPI(ctx, client.RawApiRequest{ |
| 23 | Method: method, |
| 24 | URL: path, |
| 25 | Data: body, |
| 26 | As: r.accessIdentity, |
| 27 | }) |
| 28 | if err != nil { |
| 29 | if _, ok := errs.ProblemOf(err); ok { |
| 30 | return nil, err |
| 31 | } |
| 32 | return nil, errs.NewNetworkError(errs.SubtypeNetworkTransport, |
| 33 | "api %s %s: %s", method, path, err).WithCause(err) |
| 34 | } |
| 35 | // Non-JSON HTTP errors (gateway text/plain 404 etc.) skip OAPI envelope parsing. |
| 36 | ct := resp.Header.Get("Content-Type") |
| 37 | if resp.StatusCode >= 400 && !client.IsJSONContentType(ct) && ct != "" { |
| 38 | const maxBodyEcho = 256 |
| 39 | body := string(resp.RawBody) |
| 40 | if len(body) > maxBodyEcho { |
| 41 | body = body[:maxBodyEcho] + "…(truncated)" |
| 42 | } |
| 43 | if resp.StatusCode >= 500 { |
| 44 | return nil, errs.NewNetworkError(errs.SubtypeNetworkServer, |
| 45 | "api %s %s returned %d: %s", method, path, resp.StatusCode, body).WithRetryable() |
| 46 | } |
| 47 | return nil, errs.NewInternalError(errs.SubtypeInvalidResponse, |
| 48 | "api %s %s returned %d: %s", method, path, resp.StatusCode, body) |
| 49 | } |
| 50 | result, err := client.ParseJSONResponse(resp) |
| 51 | if err != nil { |
| 52 | if _, ok := errs.ProblemOf(err); ok { |
| 53 | return nil, err |
| 54 | } |
| 55 | return nil, errs.NewInternalError(errs.SubtypeInvalidResponse, |
| 56 | "api %s %s: %s", method, path, err).WithCause(err) |
| 57 | } |
| 58 | if apiErr := r.client.CheckResponse(result, r.accessIdentity); apiErr != nil { |
| 59 | return json.RawMessage(resp.RawBody), apiErr |
| 60 | } |
| 61 | return json.RawMessage(resp.RawBody), nil |
| 62 | } |
nothing calls this directly
no test coverage detected