-
Notifications
You must be signed in to change notification settings - Fork 113
/
Copy patherrtypes.go
197 lines (147 loc) · 7.11 KB
/
errtypes.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
186
187
188
189
190
191
192
193
194
195
196
197
// Copyright 2018-2024 CERN
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// In applying this license, CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
// Package errtypes contains definitions for common errors.
// It would have nice to call this package errors, err or error
// but errors clashes with github.com/pkg/errors, err is used for any error variable
// and error is a reserved word :)
package errtypes
// NotFound is the error to use when something is not found.
type NotFound string
func (e NotFound) Error() string { return "error: not found: " + string(e) }
// IsNotFound implements the IsNotFound interface.
func (e NotFound) IsNotFound() {}
// InternalError is the error to use when we really don't know what happened. Use with care.
type InternalError string
func (e InternalError) Error() string { return "internal error: " + string(e) }
// IsInternalError implements the IsInternalError interface.
func (e InternalError) IsInternalError() {}
// PermissionDenied is the error to use when a resource cannot be access because of missing permissions.
type PermissionDenied string
func (e PermissionDenied) Error() string { return "error: permission denied: " + string(e) }
// IsPermissionDenied implements the IsPermissionDenied interface.
func (e PermissionDenied) IsPermissionDenied() {}
// AlreadyExists is the error to use when a resource already exists and can't be overwritten.
type AlreadyExists string
func (e AlreadyExists) Error() string { return "error: already exists: " + string(e) }
// IsAlreadyExists implements the IsAlreadyExists interface.
func (e AlreadyExists) IsAlreadyExists() {}
// UserRequired represents an error when a user could not be found from the context.
type UserRequired string
func (e UserRequired) Error() string { return "error: user required: " + string(e) }
// IsUserRequired implements the IsUserRequired interface.
func (e UserRequired) IsUserRequired() {}
// InvalidCredentials is the error to use when receiving invalid credentials.
type InvalidCredentials string
func (e InvalidCredentials) Error() string { return "error: invalid credentials: " + string(e) }
// IsInvalidCredentials implements the IsInvalidCredentials interface.
func (e InvalidCredentials) IsInvalidCredentials() {}
// NotSupported is the error to use when an action is not supported.
type NotSupported string
func (e NotSupported) Error() string { return "error: not supported: " + string(e) }
// IsNotSupported implements the IsNotSupported interface.
func (e NotSupported) IsNotSupported() {}
// PartialContent is the error to use when the client request has partial data.
type PartialContent string
func (e PartialContent) Error() string { return "error: partial content: " + string(e) }
// IsPartialContent implements the IsPartialContent interface.
func (e PartialContent) IsPartialContent() {}
// BadRequest is the error to use when the server cannot or will not process the request (due to a client error). Reauthenticating won't help.
type BadRequest string
func (e BadRequest) Error() string { return "error: bad request: " + string(e) }
// IsBadRequest implements the IsBadRequest interface.
func (e BadRequest) IsBadRequest() {}
// Conflict is the error to use when the server found a conflict when processing the request (e.g. with an existing lock).
type Conflict string
func (e Conflict) Error() string { return "error: conflict: " + string(e) }
// IsConflict implements the IsConflict interface.
func (e Conflict) IsConflict() {}
// ChecksumMismatch is the error to use when the sent hash does not match the calculated hash.
type ChecksumMismatch string
func (e ChecksumMismatch) Error() string { return "error: checksum mismatch: " + string(e) }
// IsChecksumMismatch implements the IsChecksumMismatch interface.
func (e ChecksumMismatch) IsChecksumMismatch() {}
// StatusChecksumMismatch 419 is an unofficial http status code in an unassigned range that is used for checksum mismatches
// Proposed by https://stackoverflow.com/a/35665694
// Official HTTP status code registry: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
// Note: TUS uses unassigned 460 Checksum-Mismatch
// RFC proposal for checksum digest uses a `Want-Digest` header: https://tools.ietf.org/html/rfc3230
// oc clienst issue: https://github.com/owncloud/core/issues/22711
const StatusChecksumMismatch = 419
// InsufficientStorage is the error to use when there is insufficient storage.
type InsufficientStorage string
func (e InsufficientStorage) Error() string { return "error: insufficient storage: " + string(e) }
// IsInsufficientStorage implements the IsInsufficientStorage interface.
func (e InsufficientStorage) IsInsufficientStorage() {}
// StatusInssufficientStorage 507 is an official http status code to indicate that there is insufficient storage
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/507
const StatusInssufficientStorage = 507
// IsNotFound is the interface to implement
// to specify that an a resource is not found.
type IsNotFound interface {
IsNotFound()
}
// IsAlreadyExists is the interface to implement
// to specify that a resource already exists.
type IsAlreadyExists interface {
IsAlreadyExists()
}
// IsInternalError is the interface to implement
// to specify that there was some internal error.
type IsInternalError interface {
IsInternalError()
}
// IsUserRequired is the interface to implement
// to specify that a user is required.
type IsUserRequired interface {
IsUserRequired()
}
// IsInvalidCredentials is the interface to implement
// to specify that credentials were wrong.
type IsInvalidCredentials interface {
IsInvalidCredentials()
}
// IsNotSupported is the interface to implement
// to specify that an action is not supported.
type IsNotSupported interface {
IsNotSupported()
}
// IsPermissionDenied is the interface to implement
// to specify that an action is denied.
type IsPermissionDenied interface {
IsPermissionDenied()
}
// IsPartialContent is the interface to implement
// to specify that the client request has partial data.
type IsPartialContent interface {
IsPartialContent()
}
// IsBadRequest is the interface to implement
// to specify that the server cannot or will not process the request.
type IsBadRequest interface {
IsBadRequest()
}
// IsChecksumMismatch is the interface to implement
// to specify that a checksum does not match.
type IsChecksumMismatch interface {
IsChecksumMismatch()
}
// IsInsufficientStorage is the interface to implement
// to specify that there is insufficient storage.
type IsInsufficientStorage interface {
IsInsufficientStorage()
}