-
Notifications
You must be signed in to change notification settings - Fork 14
/
errors.go
90 lines (77 loc) · 2.51 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
78
79
80
81
82
83
84
85
86
87
88
89
90
package claim
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// CodeType is the error code type for the module
type CodeType = sdk.CodeType
// Claim error types
const (
DefaultCodespace sdk.CodespaceType = ModuleName
ErrorCodeInvalidBodyTooShort CodeType = 101
ErrorCodeInvalidBodyTooLong CodeType = 102
ErrorCodeInvalidID CodeType = 103
ErrorCodeNotFound CodeType = 104
ErrorCodeInvalidSType CodeType = 105
ErrorCodeClaimsWithCommunityNotFound CodeType = 106
ErrorCodeInvalidSourceURL CodeType = 107
ErrorCodeCreatorJailed CodeType = 108
ErrorCodeAddressNotAuthorised CodeType = 109
ErrorCodeJSONParsing CodeType = 110
)
// ErrInvalidBodyTooShort throws an error on invalid claim body
func ErrInvalidBodyTooShort(body string) sdk.Error {
return sdk.NewError(
DefaultCodespace,
ErrorCodeInvalidBodyTooShort,
"Invalid claim body, too short: "+body)
}
// ErrInvalidBodyTooLong throws an error on invalid claim body
func ErrInvalidBodyTooLong() sdk.Error {
return sdk.NewError(
DefaultCodespace,
ErrorCodeInvalidBodyTooLong,
"Invalid claim body, too long")
}
// ErrUnknownClaim throws an error on an unknown claim id
func ErrUnknownClaim(id uint64) sdk.Error {
return sdk.NewError(
DefaultCodespace,
ErrorCodeInvalidID,
fmt.Sprintf("Unknown claim id: %d", id))
}
// ErrInvalidCommunityID throws an error on invalid community id
func ErrInvalidCommunityID(id string) sdk.Error {
return sdk.NewError(
DefaultCodespace,
ErrorCodeClaimsWithCommunityNotFound,
fmt.Sprintf("Invalid community id: %s", id))
}
// ErrInvalidSourceURL throws an error when a URL in invalid
func ErrInvalidSourceURL(url string) sdk.Error {
return sdk.NewError(
DefaultCodespace,
ErrorCodeInvalidSourceURL,
"Invalid source URL: "+url)
}
// ErrCreatorJailed throws an error on jailed creator
func ErrCreatorJailed(addr sdk.AccAddress) sdk.Error {
return sdk.NewError(
DefaultCodespace,
ErrorCodeCreatorJailed,
"Creator cannot be jailed: "+addr.String())
}
// ErrAddressNotAuthorised throws an error when the address is not admin
func ErrAddressNotAuthorised() sdk.Error {
return sdk.NewError(
DefaultCodespace,
ErrorCodeAddressNotAuthorised,
"This address is not authorised to perform this action.")
}
// ErrJSONParse throws an error on failed JSON parsing
func ErrJSONParse(err error) sdk.Error {
return sdk.NewError(
DefaultCodespace,
ErrorCodeJSONParsing,
"JSON parsing error: "+err.Error())
}