Skip to content

Commit

Permalink
fix GetProject and UpdateRetentionPolicy not returning proper errors
Browse files Browse the repository at this point in the history
  • Loading branch information
elenz97 committed Jan 12, 2024
1 parent 1bd1aeb commit c1da600
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions apiv2/pkg/clients/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package project
import (
"context"
goerr "errors"

projectapi "github.com/mittwald/goharbor-client/v5/apiv2/internal/api/client/project"
"github.com/mittwald/goharbor-client/v5/apiv2/pkg/config"
"github.com/mittwald/goharbor-client/v5/apiv2/pkg/errors"
Expand Down Expand Up @@ -109,12 +108,13 @@ func (c *RESTClient) GetProject(ctx context.Context, nameOrID string) (*model.Pr

resp, err := c.V2Client.Project.GetProject(params, c.AuthInfo)
if err != nil {
if resp == nil {
return nil, &errors.ErrProjectNotFound{}
}
return nil, handleSwaggerProjectErrors(err)
}

if resp == nil {
return nil, &errors.ErrProjectNotFound{}
}

return resp.Payload, nil
}

Expand Down
2 changes: 1 addition & 1 deletion apiv2/pkg/clients/project/project_errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func handleSwaggerProjectErrors(in error) error {
case http.StatusForbidden:
return &errors.ErrProjectNoPermission{}
case http.StatusNotFound:
return &errors.ErrProjectUnknownResource{}
return &errors.ErrProjectNotFound{}
case http.StatusInternalServerError:
return &errors.ErrProjectInternalErrors{}
}
Expand Down
10 changes: 5 additions & 5 deletions apiv2/pkg/clients/retention/retention.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
clienterrors "github.com/mittwald/goharbor-client/v5/apiv2/pkg/errors"
"strconv"

"github.com/go-openapi/runtime"
Expand Down Expand Up @@ -186,15 +187,14 @@ func (c *RESTClient) UpdateRetentionPolicy(ctx context.Context, ret *modelv2.Ret
params.WithTimeout(c.Options.Timeout)

resp, err := c.V2Client.Retention.UpdateRetention(params, c.AuthInfo)

if resp == nil {
return &ErrRetentionDoesNotExist{}
}

if err != nil {
return handleSwaggerRetentionErrors(err)
}

if resp == nil {
return &clienterrors.ErrNotFound{}
}

return nil
}

Expand Down

0 comments on commit c1da600

Please sign in to comment.