-
Notifications
You must be signed in to change notification settings - Fork 50
/
project_errors.go
46 lines (41 loc) · 1.3 KB
/
project_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
41
42
43
44
45
46
package project
import (
"net/http"
"github.com/go-openapi/runtime"
projectapi "github.com/mittwald/goharbor-client/v5/apiv2/internal/api/client/project"
"github.com/mittwald/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 handleSwaggerProjectErrors(in error) error {
t, ok := in.(*runtime.APIError)
if ok {
switch t.Code {
case http.StatusCreated:
// Harbor sometimes returns 201 instead of 200 despite the swagger spec
// not declaring it.
return nil
case http.StatusBadRequest:
return &errors.ErrProjectIllegalIDFormat{}
case http.StatusUnauthorized:
return &errors.ErrUnauthorized{}
case http.StatusForbidden:
return &errors.ErrProjectNoPermission{}
case http.StatusNotFound:
return &errors.ErrProjectUnknownResource{}
case http.StatusInternalServerError:
return &errors.ErrProjectInternalErrors{}
}
}
switch in.(type) {
case *projectapi.DeleteProjectNotFound:
return &errors.ErrProjectIDNotExists{}
case *projectapi.UpdateProjectNotFound:
return &errors.ErrProjectIDNotExists{}
case *projectapi.CreateProjectConflict:
return &errors.ErrProjectNameAlreadyExists{}
default:
return in
}
}