forked from mittwald/goharbor-client
/
member_errors.go
40 lines (35 loc) · 1.01 KB
/
member_errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package member
import (
"net/http"
"github.com/go-openapi/runtime"
"github.com/xuesea/goharbor-client/v5/apiv2/internal/api/client/member"
"github.com/xuesea/goharbor-client/v5/apiv2/pkg/errors"
)
// handleSwaggerProjectErrors takes a swagger generated error as input,
// which usually does not contain any form of error message,
// and outputs a new error with a proper message.
func handleSwaggerMemberErrors(in error) error {
t, ok := in.(*runtime.APIError)
if ok {
switch t.Code {
case http.StatusCreated:
// Harbor sometimes return 201 instead of 200 despite the swagger spec
// not declaring it.
return nil
case http.StatusBadRequest:
return &errors.ErrBadRequest{}
case http.StatusUnauthorized:
return &errors.ErrUnauthorized{}
case http.StatusForbidden:
return &errors.ErrForbidden{}
case http.StatusNotFound:
return &errors.ErrNotFound{}
}
}
switch in.(type) {
default:
return in
case *member.CreateProjectMemberConflict:
return &errors.ErrMemberAlreadyExists{}
}
}