forked from xoanmi/goharbor-client
/
artifact_errors.go
35 lines (31 loc) · 977 Bytes
/
artifact_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
package artifact
import (
"net/http"
"github.com/go-openapi/runtime"
"github.com/peresureda/goharbor-client/v5/apiv2/pkg/errors"
)
// handleSwaggerArtifactErrors 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 handleSwaggerArtifactErrors(in error) error {
t, ok := in.(*runtime.APIError)
if ok {
switch t.Code {
// As per documentation '200' should be the status code for success,
// yet the API returns status code '201' when creating a GC schedule succeeds.
case http.StatusCreated:
return nil
case http.StatusBadRequest:
return &errors.ErrBadRequest{}
case http.StatusUnauthorized:
return &errors.ErrUnauthorized{}
case http.StatusForbidden:
return &errors.ErrForbidden{}
case http.StatusConflict:
return &errors.ErrConflict{}
case http.StatusInternalServerError:
return &errors.ErrInternalErrors{}
}
}
return in
}