-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
62 lines (52 loc) · 1.31 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
package dhstore
import (
"fmt"
"net/http"
"github.com/mr-tron/base58"
"github.com/multiformats/go-multicodec"
"github.com/multiformats/go-multihash"
)
type (
ErrUnsupportedMulticodecCode struct {
Code multicodec.Code
}
ErrMultihashDecode struct {
Mh multihash.Multihash
Err error
}
ErrInvalidHashedValueKey struct {
Key HashedValueKey
Err error
}
ErrHttpResponse struct {
Message string
Status int
}
)
func (e ErrUnsupportedMulticodecCode) Error() string {
return fmt.Sprintf("multihash must be of code dbl-sha2-256, got: %s", e.Code.String())
}
func (e ErrMultihashDecode) Error() string {
if e.Err != nil {
return fmt.Sprintf("failed to decode multihash %s: %s", e.Mh.B58String(), e.Err.Error())
}
return fmt.Sprintf("failed to decode multihash %s", e.Mh.B58String())
}
func (e ErrMultihashDecode) Unwrap() error {
return e.Err
}
func (e ErrInvalidHashedValueKey) Error() string {
if e.Err != nil {
return fmt.Sprintf("invalid hashed value key %s: %s", base58.Encode(e.Key), e.Err.Error())
}
return fmt.Sprintf("invalid hashed value key %s", base58.Encode(e.Key))
}
func (e ErrInvalidHashedValueKey) Unwrap() error {
return e.Err
}
func (e ErrHttpResponse) Error() string {
return e.Message
}
func (e ErrHttpResponse) WriteTo(w http.ResponseWriter) {
http.Error(w, e.Message, e.Status)
}