From c1da600eb4e308a9e4417441b87aa3258084bcad Mon Sep 17 00:00:00 2001 From: Eike David Lenz Date: Fri, 12 Jan 2024 07:23:22 +0100 Subject: [PATCH] fix GetProject and UpdateRetentionPolicy not returning proper errors --- apiv2/pkg/clients/project/project.go | 8 ++++---- apiv2/pkg/clients/project/project_errors.go | 2 +- apiv2/pkg/clients/retention/retention.go | 10 +++++----- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/apiv2/pkg/clients/project/project.go b/apiv2/pkg/clients/project/project.go index 04606dc6..188887ae 100644 --- a/apiv2/pkg/clients/project/project.go +++ b/apiv2/pkg/clients/project/project.go @@ -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" @@ -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 } diff --git a/apiv2/pkg/clients/project/project_errors.go b/apiv2/pkg/clients/project/project_errors.go index 062b0449..79465266 100644 --- a/apiv2/pkg/clients/project/project_errors.go +++ b/apiv2/pkg/clients/project/project_errors.go @@ -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{} } diff --git a/apiv2/pkg/clients/retention/retention.go b/apiv2/pkg/clients/retention/retention.go index 2b4a10e2..7848ad2c 100644 --- a/apiv2/pkg/clients/retention/retention.go +++ b/apiv2/pkg/clients/retention/retention.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + clienterrors "github.com/mittwald/goharbor-client/v5/apiv2/pkg/errors" "strconv" "github.com/go-openapi/runtime" @@ -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 }