generated from cheqd/.github
-
Notifications
You must be signed in to change notification settings - Fork 5
/
errors.go
77 lines (63 loc) · 2.58 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
70
71
72
73
74
75
76
77
package types
import (
"errors"
"fmt"
)
type IdentityError struct {
Code int
Message string
Internal error
Did string
ContentType ContentType
IsDereferencing bool
}
// Error makes it compatible with `error` interface.
func (he *IdentityError) Error() string {
return fmt.Sprintf("code=%d, message=%s", he.Code, he.Message)
}
func (e IdentityError) GetResolutionOutput() ResolutionResultI {
metadata := NewResolutionMetadata(e.Did, e.ContentType, e.Message)
return DidResolution{ResolutionMetadata: metadata}
}
func (e IdentityError) GetDereferencingOutput() ResolutionResultI {
metadata := NewDereferencingMetadata(e.Did, e.ContentType, e.Message)
return DidDereferencing{DereferencingMetadata: metadata}
}
func (e *IdentityError) DisplayMessage() ResolutionResultI {
if e.IsDereferencing {
return e.GetDereferencingOutput()
}
return e.GetResolutionOutput()
}
func NewIdentityError(code int, message string, isDereferencing bool, did string, contentType ContentType, err error) *IdentityError {
e := IdentityError{
Code: code,
Message: message,
Internal: err,
Did: did,
ContentType: contentType,
IsDereferencing: isDereferencing,
}
return &e
}
func NewInvalidDIDError(did string, contentType ContentType, err error, isDereferencing bool) *IdentityError {
return NewIdentityError(400, "invalidDid", isDereferencing, did, contentType, err)
}
func NewInvalidDIDUrlError(did string, contentType ContentType, err error, isDereferencing bool) *IdentityError {
return NewIdentityError(400, "invalidDidUrl", isDereferencing, did, contentType, err)
}
func NewNotFoundError(did string, contentType ContentType, err error, isDereferencing bool) *IdentityError {
return NewIdentityError(404, "notFound", isDereferencing, did, contentType, err)
}
func NewRepresentationNotSupportedError(did string, contentType ContentType, err error, isDereferencing bool) *IdentityError {
return NewIdentityError(406, "representationNotSupported", isDereferencing, did, contentType, err)
}
func NewMethodNotSupportedError(did string, contentType ContentType, err error, isDereferencing bool) *IdentityError {
return NewIdentityError(406, "methodNotSupported", isDereferencing, did, contentType, err)
}
func NewInternalError(did string, contentType ContentType, err error, isDereferencing bool) *IdentityError {
return NewIdentityError(500, "internalError", isDereferencing, did, contentType, err)
}
func NewInvalidIdentifierError() error {
return errors.New("unique id should be one of: 16 bytes of decoded base58 string or UUID")
}