/
errors.go
43 lines (33 loc) · 959 Bytes
/
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
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package dynamicdiscovery
import (
"strings"
"github.com/pkg/errors"
)
const (
// AccessDenied indicates that the user does not have permission to perform the operation
AccessDenied = "access denied"
)
// DiscoveryError is an error originating at the Discovery service
type DiscoveryError struct {
error
target string
}
//Error returns string representation with target
func (e DiscoveryError) Error() string {
return errors.Wrapf(e.error, "target [%s]", e.target).Error()
}
//Target returns url of the peer
func (e DiscoveryError) Target() string {
return e.target
}
//IsAccessDenied checks if response contains access denied msg
func (e DiscoveryError) IsAccessDenied() bool {
return strings.Contains(e.Error(), AccessDenied)
}
func newDiscoveryError(err error, target string) error {
return DiscoveryError{target: target, error: err}
}