mirror of
https://github.com/portainer/portainer.git
synced 2025-07-25 08:19:40 +02:00
fix(edgestack): incorrect response code (#8873)
This commit is contained in:
parent
19eceaf37f
commit
ed279ba65b
4 changed files with 46 additions and 28 deletions
|
@ -8,6 +8,8 @@ import (
|
|||
"github.com/portainer/portainer/api/dataservices"
|
||||
)
|
||||
|
||||
var ErrEdgeGroupNotFound = errors.New("Edge group was not found")
|
||||
|
||||
// EdgeStackRelatedEndpoints returns a list of environments(endpoints) related to this Edge stack
|
||||
func EdgeStackRelatedEndpoints(edgeGroupIDs []portainer.EdgeGroupID, endpoints []portainer.Endpoint, endpointGroups []portainer.EndpointGroup, edgeGroups []portainer.EdgeGroup) ([]portainer.EndpointID, error) {
|
||||
edgeStackEndpoints := []portainer.EndpointID{}
|
||||
|
@ -23,7 +25,7 @@ func EdgeStackRelatedEndpoints(edgeGroupIDs []portainer.EdgeGroupID, endpoints [
|
|||
}
|
||||
|
||||
if edgeGroup == nil {
|
||||
return nil, errors.New("Edge group was not found")
|
||||
return nil, ErrEdgeGroupNotFound
|
||||
}
|
||||
|
||||
edgeStackEndpoints = append(edgeStackEndpoints, EdgeGroupRelatedEndpoints(edgeGroup, endpoints, endpointGroups)...)
|
||||
|
|
15
api/internal/edge/edgestacks/error.go
Normal file
15
api/internal/edge/edgestacks/error.go
Normal file
|
@ -0,0 +1,15 @@
|
|||
package edgestacks
|
||||
|
||||
type InvalidPayloadError struct {
|
||||
msg string
|
||||
}
|
||||
|
||||
func (e *InvalidPayloadError) Error() string {
|
||||
return e.msg
|
||||
}
|
||||
|
||||
func NewInvalidPayloadError(errMsg string) *InvalidPayloadError {
|
||||
return &InvalidPayloadError{
|
||||
msg: errMsg,
|
||||
}
|
||||
}
|
|
@ -80,6 +80,9 @@ func (service *Service) PersistEdgeStack(
|
|||
|
||||
relatedEndpointIds, err := edge.EdgeStackRelatedEndpoints(stack.EdgeGroups, relationConfig.Endpoints, relationConfig.EndpointGroups, relationConfig.EdgeGroups)
|
||||
if err != nil {
|
||||
if err == edge.ErrEdgeGroupNotFound {
|
||||
return nil, NewInvalidPayloadError(err.Error())
|
||||
}
|
||||
return nil, fmt.Errorf("unable to persist environment relation in database: %w", err)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue