MCPcopy Create free account
hub / github.com/bytebase/bytebase / callAPI

Method callAPI

backend/api/mcp/tool_change.go:542–557  ·  view source on GitHub ↗

callAPI calls an API endpoint, checks the response, and extracts the resource name. Handles permission errors, HTTP errors, and JSON parsing in one place.

(ctx context.Context, path, operation, permission string, body map[string]any)

Source from the content-addressed store, hash-verified

540// callAPI calls an API endpoint, checks the response, and extracts the resource name.
541// Handles permission errors, HTTP errors, and JSON parsing in one place.
542func (s *Server) callAPI(ctx context.Context, path, operation, permission string, body map[string]any) (string, error) {
543 resp, err := s.apiRequest(ctx, path, body)
544 if err != nil {
545 return "", errors.Wrapf(err, "%s request failed", operation)
546 }
547 if err := checkAPIResponse(resp, operation, permission); err != nil {
548 return "", err
549 }
550 var result struct {
551 Name string `json:"name"`
552 }
553 if err := json.Unmarshal(resp.Body, &result); err != nil {
554 return "", errors.Wrapf(err, "failed to parse %s response", operation)
555 }
556 return result.Name, nil
557}
558
559// checkAPIResponse checks an API response for permission or general errors.
560// Returns nil if the response is OK, or a structured error otherwise.

Callers 3

createSheetMethod · 0.95
createPlanMethod · 0.95
createRolloutMethod · 0.95

Calls 3

apiRequestMethod · 0.95
checkAPIResponseFunction · 0.85
UnmarshalMethod · 0.80

Tested by

no test coverage detected