-
Notifications
You must be signed in to change notification settings - Fork 23
/
errors.go
69 lines (55 loc) · 1.95 KB
/
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
// Copyright 2018 Bull S.A.S. Atos Technologies - Bull, Rue Jean Jaures, B.P.68, 78340, Les Clayes-sous-Bois, France.
//
// 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.
package hostspool
import (
"github.com/pkg/errors"
)
type hostNotFoundError struct{}
func (e hostNotFoundError) Error() string {
return "host not found in pool"
}
// IsHostNotFoundError checks if an error is an "host not found" error
func IsHostNotFoundError(err error) bool {
_, ok := errors.Cause(err).(hostNotFoundError)
return ok
}
type hostAlreadyExistError struct{}
func (e hostAlreadyExistError) Error() string {
return "a host with the same name already exists in the pool"
}
// IsHostAlreadyExistError checks if an error is an "host already exists" error
func IsHostAlreadyExistError(err error) bool {
_, ok := errors.Cause(err).(hostAlreadyExistError)
return ok
}
type badRequestError struct {
msg string
}
func (e badRequestError) Error() string {
return e.msg
}
// IsBadRequestError checks if an error is an error due to a bad input
func IsBadRequestError(err error) bool {
_, ok := errors.Cause(err).(badRequestError)
return ok
}
type noMatchingHostFoundError struct{}
func (e noMatchingHostFoundError) Error() string {
return "no matching host found"
}
// IsNoMatchingHostFoundError checks if an error is an error due to no hosts match the given filters if any
func IsNoMatchingHostFoundError(err error) bool {
_, ok := errors.Cause(err).(noMatchingHostFoundError)
return ok
}