Skip to content

Commit c1da600

Browse files
committed
fix GetProject and UpdateRetentionPolicy not returning proper errors
1 parent 1bd1aeb commit c1da600

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

apiv2/pkg/clients/project/project.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package project
33
import (
44
"context"
55
goerr "errors"
6-
76
projectapi "github.com/mittwald/goharbor-client/v5/apiv2/internal/api/client/project"
87
"github.com/mittwald/goharbor-client/v5/apiv2/pkg/config"
98
"github.com/mittwald/goharbor-client/v5/apiv2/pkg/errors"
@@ -109,12 +108,13 @@ func (c *RESTClient) GetProject(ctx context.Context, nameOrID string) (*model.Pr
109108

110109
resp, err := c.V2Client.Project.GetProject(params, c.AuthInfo)
111110
if err != nil {
112-
if resp == nil {
113-
return nil, &errors.ErrProjectNotFound{}
114-
}
115111
return nil, handleSwaggerProjectErrors(err)
116112
}
117113

114+
if resp == nil {
115+
return nil, &errors.ErrProjectNotFound{}
116+
}
117+
118118
return resp.Payload, nil
119119
}
120120

apiv2/pkg/clients/project/project_errors.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func handleSwaggerProjectErrors(in error) error {
2727
case http.StatusForbidden:
2828
return &errors.ErrProjectNoPermission{}
2929
case http.StatusNotFound:
30-
return &errors.ErrProjectUnknownResource{}
30+
return &errors.ErrProjectNotFound{}
3131
case http.StatusInternalServerError:
3232
return &errors.ErrProjectInternalErrors{}
3333
}

apiv2/pkg/clients/retention/retention.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
clienterrors "github.com/mittwald/goharbor-client/v5/apiv2/pkg/errors"
78
"strconv"
89

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

188189
resp, err := c.V2Client.Retention.UpdateRetention(params, c.AuthInfo)
189-
190-
if resp == nil {
191-
return &ErrRetentionDoesNotExist{}
192-
}
193-
194190
if err != nil {
195191
return handleSwaggerRetentionErrors(err)
196192
}
197193

194+
if resp == nil {
195+
return &clienterrors.ErrNotFound{}
196+
}
197+
198198
return nil
199199
}
200200

0 commit comments

Comments
 (0)