wso2 / wso2/api-platform

Errors are not propagated via APIs properly

Open
#405 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area/Management Aspect/API Severity/Major
Dominant language
Go
Stars
71
Forks
111
Avg merge
1d 14h
Merged PRs (30d)
110

Description

Please select the area the issue is related to

Area/Management (Management API or Management Portal UI)

Please select the aspect the issue is related to

Aspect/API (API backends, definitions, contracts, interfaces, OpenAPI)

Description

When errors are captured at downstream methods, they are ignored and new/generic errors are passed via the REST APIs making it hard to capture the orginal error.

Steps to Reproduce
  1. Create an API without backends
  2. Deploy it to a gateway

Error shown via the REST APIs:

{
    "code": 400,
    "message": "Bad Request",
    "description": "Invalid API deployment configuration"
}

Actual error:

// validateDeploymentRequest validates the deployment request
func (s *APIService) validateDeploymentRequest(req *dto.APIRevisionDeployment, apiId, orgId string) error {
	if req.GatewayID == "" {
		return errors.New("gateway Id is required")
	}
	if req.VHost == "" {
		return errors.New("vhost is required")
	}
	// TODO - vHost validation
	gateway, err := s.gatewayRepo.GetByUUID(req.GatewayID)
	if err != nil {
		return fmt.Errorf("failed to get gateway: %w", err)
	}
	if gateway == nil {
		return fmt.Errorf("failed to get gateway: %w", err)
	}
	if gateway.OrganizationID != orgId {
		return fmt.Errorf("failed to get gateway: %w", err)
	}

	// Validate that the API has at least one backend service attached
	backendServices, err := s.backendServiceRepo.GetBackendServicesByAPIID(apiId)
	if err != nil {
		return fmt.Errorf("failed to get backend services for API: %w", err)
	}
	if len(backendServices) == 0 {              <<<<<<<<<<<<<<<<<
		return errors.New("API must have at least one backend service attached before deployment")
	}

Severity Level of the Issue

Severity/Major (Important functionality is broken. Should be prioritized. Doesn't need immediate attention)

Environment Details (with versions)

No response

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The reported path is APIService.validateDeploymentRequest, including gatewayRepo.GetByUUID and backendServiceRepo.GetBackendServicesByAPIID; start there and trace how returned errors become REST responses. Review the existing API error-response handling, then verify that downstream validation errors reach the API response with their useful message instead of a generic deployment error.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.