-
Notifications
You must be signed in to change notification settings - Fork 50
/
auditlog_errors.go
38 lines (33 loc) · 1.04 KB
/
auditlog_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
package auditlog
import (
"net/http"
"github.com/go-openapi/runtime"
"github.com/mittwald/goharbor-client/v5/apiv2/internal/api/client/auditlog"
"github.com/mittwald/goharbor-client/v5/apiv2/pkg/errors"
)
// handleSwaggerAuditLogErrors 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 handleSwaggerAuditLogErrors(in error) error {
t, ok := in.(*runtime.APIError)
if ok {
switch t.Code {
case http.StatusBadRequest:
return &errors.ErrAuditLogBadRequest{}
case http.StatusUnauthorized:
return &errors.ErrAuditLogUnauthorized{}
case http.StatusInternalServerError:
return &errors.ErrAuditLogInternalServerError{}
}
}
switch in.(type) {
case *auditlog.ListAuditLogsInternalServerError:
return &errors.ErrAuditLogInternalServerError{}
case *auditlog.ListAuditLogsBadRequest:
return &errors.ErrAuditLogBadRequest{}
case *auditlog.ListAuditLogsUnauthorized:
return &errors.ErrAuditLogUnauthorized{}
default:
return in
}
}