-
Notifications
You must be signed in to change notification settings - Fork 50
/
replication_errors.go
185 lines (144 loc) · 6.08 KB
/
replication_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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
package replication
import (
"net/http"
"github.com/go-openapi/runtime"
replicationapi "github.com/mittwald/goharbor-client/v5/apiv2/internal/api/client/replication"
"github.com/mittwald/goharbor-client/v5/apiv2/pkg/errors"
)
const (
// ErrReplicationIllegalIDFormatMsg describes an illegal request format
ErrReplicationIllegalIDFormatMsg = "illegal format of provided ID value"
// ErrReplicationUnauthorizedMsg describes an unauthorized request
ErrReplicationUnauthorizedMsg = "unauthorized"
// ErrReplicationInternalErrorsMsg describes server-side internal errors
ErrReplicationInternalErrorsMsg = "unexpected internal errors"
// ErrReplicationNoPermissionMsg describes a request error without permission
ErrReplicationNoPermissionMsg = "user does not have permission to the replication"
// ErrReplicationIDNotExistsMsg describes an error
// when no proper replication ID is found
ErrReplicationIDNotExistsMsg = "replication ID does not exist"
// ErrReplicationNameAlreadyExistsMsg describes a duplicate replication name error
ErrReplicationNameAlreadyExistsMsg = "replication name already exists"
// ErrReplicationMismatchMsg describes a failed lookup
// of a replication with name/id pair
ErrReplicationMismatchMsg = "id/name pair not found on server side"
// ErrReplicationNotFoundMsg describes an error
// when a specific replication is not found
ErrReplicationNotFoundMsg = "replication not found on server side"
// ErrReplicationNotProvidedMsg describes an error
// caused by a missing replication object
ErrReplicationNotProvidedMsg = "no replication provided"
// ErrReplicationExecutionNotProvidedMsg describes an error
// caused by a missing replication execution object
ErrReplicationExecutionNotProvidedMsg = "no replication execution provided"
// ErrReplicationExecutionReplicationIDMismatchMsg describes an error
// caused by an ID mismatch of the desired replication execution and an existing replication
ErrReplicationExecutionReplicationIDMismatchMsg = "received replication execution id doesn't match"
// ErrReplicationDisabledMsg describes an error when actions cannot be performed
// because the underlying replication is currently disabled.
ErrReplicationDisabledMsg = "the underlying replication is disabled"
)
// ErrReplicationIllegalIDFormat describes an illegal request format.
type ErrReplicationIllegalIDFormat struct{}
// Error returns the error message.
func (e *ErrReplicationIllegalIDFormat) Error() string {
return ErrReplicationIllegalIDFormatMsg
}
// ErrReplicationUnauthorized describes an unauthorized request.
type ErrReplicationUnauthorized struct{}
// Error returns the error message.
func (e *ErrReplicationUnauthorized) Error() string {
return ErrReplicationUnauthorizedMsg
}
// ErrReplicationInternalErrors describes server-side internal errors.
type ErrReplicationInternalErrors struct{}
// Error returns the error message.
func (e *ErrReplicationInternalErrors) Error() string {
return ErrReplicationInternalErrorsMsg
}
// ErrReplicationNoPermission describes a request error without permission.
type ErrReplicationNoPermission struct{}
// Error returns the error message.
func (e *ErrReplicationNoPermission) Error() string {
return ErrReplicationNoPermissionMsg
}
// ErrReplicationIDNotExists describes an error
// when no proper replication ID is found.
type ErrReplicationIDNotExists struct{}
// Error returns the error message.
func (e *ErrReplicationIDNotExists) Error() string {
return ErrReplicationIDNotExistsMsg
}
// ErrReplicationNameAlreadyExists describes a duplicate replication name error.
type ErrReplicationNameAlreadyExists struct{}
// Error returns the error message.
func (e *ErrReplicationNameAlreadyExists) Error() string {
return ErrReplicationNameAlreadyExistsMsg
}
// ErrReplicationMismatch describes a failed lookup
// of a replication with name/id pair.
type ErrReplicationMismatch struct{}
// Error returns the error message.
func (e *ErrReplicationMismatch) Error() string {
return ErrReplicationMismatchMsg
}
// ErrReplicationNotFound describes an error
// when a specific replication is not found.
type ErrReplicationNotFound struct{}
// Error returns the error message.
func (e *ErrReplicationNotFound) Error() string {
return ErrReplicationNotFoundMsg
}
type ErrReplicationNotProvided struct{}
// Error returns the error message.
func (e *ErrReplicationNotProvided) Error() string {
return ErrReplicationNotProvidedMsg
}
type ErrReplicationExecutionNotProvided struct{}
// Error returns the error message.
func (e *ErrReplicationExecutionNotProvided) Error() string {
return ErrReplicationExecutionNotProvidedMsg
}
type ErrReplicationExecutionReplicationIDMismatch struct{}
// Error returns the error message.
func (e *ErrReplicationExecutionReplicationIDMismatch) Error() string {
return ErrReplicationExecutionReplicationIDMismatchMsg
}
// ErrReplicationDisabled describes an error that the underlying replication is disabled.
type ErrReplicationDisabled struct{}
// Error returns the error message.
func (e *ErrReplicationDisabled) Error() string {
return ErrReplicationDisabledMsg
}
// handleSwaggerReplicationErrors 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 handleSwaggerReplicationErrors(in error) error {
t, ok := in.(*runtime.APIError)
if ok {
switch t.Code {
case http.StatusBadRequest:
return &ErrReplicationIllegalIDFormat{}
case http.StatusUnauthorized:
return &ErrReplicationUnauthorized{}
case http.StatusForbidden:
return &ErrReplicationNoPermission{}
case http.StatusNotFound:
return &errors.ErrNotFound{}
case http.StatusInternalServerError:
return &ErrReplicationInternalErrors{}
case http.StatusPreconditionFailed:
return &ErrReplicationDisabled{}
}
}
switch in.(type) {
case *replicationapi.DeleteReplicationPolicyNotFound:
return &ErrReplicationIDNotExists{}
case *replicationapi.UpdateReplicationPolicyNotFound:
return &ErrReplicationIDNotExists{}
case *replicationapi.CreateReplicationPolicyConflict:
return &ErrReplicationNameAlreadyExists{}
default:
return in
}
}