-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.go
69 lines (58 loc) · 1.69 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
package opensea
import "errors"
// Common errors
var (
ErrEmptyContractAddress = errors.New("contract address cannot be empty")
ErrEmptyTokenID = errors.New("token ID cannot be empty")
ErrInvalidTimeWindow = errors.New("invalid time window: must be 24h, 7d, or 30d")
ErrInvalidLimit = errors.New("invalid limit: must be between 1 and 100")
ErrInvalidOwner = errors.New("invalid owner address")
)
// TimeWindow represents valid time windows for trending queries
type TimeWindow string
const (
TimeWindow24H TimeWindow = "24h"
TimeWindow7D TimeWindow = "7d"
TimeWindow30D TimeWindow = "30d"
)
// Validate checks if the time window is valid
func (tw TimeWindow) Validate() error {
switch tw {
case TimeWindow24H, TimeWindow7D, TimeWindow30D:
return nil
default:
return ErrInvalidTimeWindow
}
}
// OrderDirection represents valid order directions
type OrderDirection string
const (
OrderAsc OrderDirection = "asc"
OrderDesc OrderDirection = "desc"
)
// OrderBy represents valid order by fields
type OrderBy string
const (
OrderByCreatedDate OrderBy = "created_date"
OrderBySaleDate OrderBy = "sale_date"
OrderBySaleCount OrderBy = "sale_count"
OrderByPrice OrderBy = "price"
)
// Validate checks if the order direction is valid
func (od OrderDirection) Validate() error {
switch od {
case OrderAsc, OrderDesc:
return nil
default:
return errors.New("invalid order direction: must be asc or desc")
}
}
// Validate checks if the order by field is valid
func (ob OrderBy) Validate() error {
switch ob {
case OrderByCreatedDate, OrderBySaleDate, OrderBySaleCount, OrderByPrice:
return nil
default:
return errors.New("invalid order by field")
}
}