Document and return JSON data for API errors (#6938)

This commit is contained in:
Philippe Martin
2023-06-28 13:20:05 +02:00
committed by GitHub
parent c0127ce201
commit c8a1414926
3 changed files with 31 additions and 2 deletions

View File

@@ -172,6 +172,14 @@ paths:
},
"managedBy": "odo"
}
'500':
description: error getting the description of the component
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
example:
message: "error getting the description of the component"
/component/command:
post:
@@ -198,6 +206,22 @@ paths:
$ref: '#/components/schemas/GeneralSuccess'
example:
message: "push was successfully executed"
'400':
description: command name not supported
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
example:
message: "command name 'unknown' not supported. Supported values are: \"push\""
'429':
description: a push operation is not possible at this time. Please retry later
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
example:
message: "a push operation is not possible at this time. Please retry later"
components:
schemas:

View File

@@ -14,6 +14,7 @@ To see how to make this your own, look here:
- API version: 0.1
### Running the server
To run the server, follow these simple steps:

View File

@@ -57,7 +57,9 @@ func (s *DefaultApiService) ComponentCommandPost(ctx context.Context, componentC
}
default:
return openapi.Response(http.StatusBadRequest, nil), fmt.Errorf("command name %q not supported. Supported values are: %q", componentCommandPostRequest.Name, "push")
return openapi.Response(http.StatusBadRequest, openapi.GeneralError{
Message: fmt.Sprintf("command name %q not supported. Supported values are: %q", componentCommandPostRequest.Name, "push"),
}), nil
}
}
@@ -65,7 +67,9 @@ func (s *DefaultApiService) ComponentCommandPost(ctx context.Context, componentC
func (s *DefaultApiService) ComponentGet(ctx context.Context) (openapi.ImplResponse, error) {
value, _, err := describe.DescribeDevfileComponent(ctx, s.kubeClient, s.podmanClient, s.stateClient)
if err != nil {
return openapi.Response(http.StatusInternalServerError, ""), fmt.Errorf("error getting the description of the component: %w", err)
return openapi.Response(http.StatusInternalServerError, openapi.GeneralError{
Message: fmt.Sprintf("error getting the description of the component: %s", err),
}), nil
}
return openapi.Response(http.StatusOK, value), nil
}